无法在portlet中获取liferay登录用户详细信息

时间:2015-03-09 09:29:07

标签: liferay liferay-6 portlet liferay-theme

我有一个代理portlet和一个Generic portlet。在这里,我将Post数据从代理portlet发送到通用portlet。在发送数据时,我使用post方法并发送到view.jsp页面。在view.jsp中,我能够通过输入流获取表单数据。现在问题是我需要在通用portlet中获取登录用户详细信息,如果我单独运行我的通用portlet,我就能获得用户详细信息。但我从代理portlet调用view.jsp我无法获取用户详细信息。可能是未初始化的通用portlet如果我从代理porlet调用view.jsp,那么它会抛出以下错误,

9 Mar, 2015 8:35:22 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Producer-portlet] threw exception
 [An exception occurred processing JSP page /html/jsp/view.jsp at line 71

68: %>
69:
70: <%
71:  String fullname= user.getFullName();
72:  System.out.println("Full name is: "+fullname);
73:  %>
74:


Stacktrace:] with root cause
java.lang.NullPointerException
        at org.apache.jsp.html.jsp.view_jsp._jspService(view_jsp.java:254)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j
ava:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilt
erChain.java:116)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:
67)
        at $Proxy646.doFilter(Unknown Source)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilt
erChain.java:116)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:169)
        at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:123)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(Invo
kerFilterChain.java:204)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilt
erChain.java:109)
        at com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilte
r.java:74)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(Invo
kerFilterChain.java:204)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilt
erChain.java:109)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:
67)
        at $Proxy646.doFilter(Unknown Source)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilt
erChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFil
ter(InvokerFilterChain.java:165)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilt
erChain.java:96)
        at com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilte
r.java:74)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(Invo
kerFilterChain.java:204)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilt
erChain.java:109)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.ja
va:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j
ava:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:102
3)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.jav
a:589)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.lang.Thread.run(Thread.java:619) 

我的view.jsp代码是,

<%@ page import="com.liferay.portal.model.User" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="theme" %>

<portlet:defineObjects />
<theme:defineObjects />
 <%
     DataInputStream in = new DataInputStream (request.getInputStream());
     StringBuffer buffer = new StringBuffer();
        int value;
        while ((value=in.read()) != -1) {
            buffer.append((char)value);
          }
      String formData =  buffer.toString();
%>
<%
 String fullname= user.getFullName();
 System.out.println("Full name is: "+fullname);
 %>
<h1>Welcome to Liferay MVC Employee Portlet</h1>

如何从代理portlet调用view.jsp

,如何获取登录用户详细信息

1 个答案:

答案 0 :(得分:2)

您在portlet世界中失去控制权的第一件事就是您的网址。如果你通过servlet请求请求你的jsp文件(就像你在问题的评论中提到的那样),你将有一个显然绕过门户的servlet请求(门户请求将通过<portlet:actionURL .../>或{{1}生成})

因此,您提到的方法在门户网站中是完全错误的。您可以浏览<portlet:renderURL .../>并使用portlet的资源阶段。但是,出于可维护性的原因,我认为从另一个portlet的角度解决一个portlet是不好的做法,而是建议完全重新考虑这个体系结构。

由于我不完全理解潜在的问题,我不能建议改变架构的方法。