2012-04-09 27 views
1

我已经定义了一个由我的六个Portlet组成的页面,并将portal-ext.properties文件配置为我的默认页面页面。Liferay:如何在Liferay中使用RequestDispatcher重定向到公共页面

我有一个自定义登录页面接触到我的数据库,一旦用户是有效的,我使用/用户/测试/家重定向他此页,并且还使用http://localhost:8086/user/test/home

试图但这并没有奏效,我一直在得到

public void doView(RenderRequest request, RenderResponse response) 
      throws PortletException, IOException { 

     response.setContentType("text/html"); 

     System.out.println("Inside the doView Method"); 
     PortletRequestDispatcher dispatcher = null; 
     if (this.name.isEmpty()) { 
      dispatcher = getPortletContext().getRequestDispatcher(
        "/WEB-INF/jsp/AllInOne_view.jsp"); 
     } else { 
      request.setAttribute("name", this.name); 
      dispatcher = getPortletContext().getRequestDispatcher(
        "http://localhost:8086/user/test/home"); 
     } 
     this.name = ""; 
     this.action = ""; 
     dispatcher.include(request, response); 
    } 


17:53:47,765 ERROR [render_portlet_jsp:154] java.lang.NullPointerException 
    at org.ravi.learning.AllInOne.doView(AllInOne.java:57) 
    at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) 
    at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) 
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100) 
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64) 
    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:93) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) 

的AllinOne.java是我的自定义GenericPortlet类AllInOne.java:57是

dispatcher.include(request, response); 

更新部分这里

这是Java类

package org.ravi.learning; 

import java.io.IOException; 

import javax.portlet.ActionRequest; 
import javax.portlet.ActionResponse; 
import javax.portlet.GenericPortlet; 
import javax.portlet.PortletException; 
import javax.portlet.PortletRequestDispatcher; 
import javax.portlet.RenderRequest; 
import javax.portlet.RenderResponse; 

public class AllInOne extends GenericPortlet { 
    String action = ""; 
    String name = ""; 

    public void processAction(ActionRequest request, ActionResponse response) 
      throws PortletException, IOException { 

     System.out.println("Inside the Process Action Method new"); 

     this.action = request.getParameter("myAction"); 

     if (this.action.equals("formAction")) { 
      this.name = request.getParameter("personName"); 

     } 
     String urlpaths = "http://localhost:8086/user/test/home"; 
     response.sendRedirect(urlpaths); 

    } 

    public void doView(RenderRequest request, RenderResponse response) 
      throws PortletException, IOException { 

     response.setContentType("text/html"); 


    } 

} 

作为一个新的用户,我不能发表图片,请参阅该图像

http://tinypic.com/view.php?pic=a43nlv&s=5

+0

Is getPortletContext()是否返回对象?只需打印并查看返回结果 – 2012-04-10 05:46:07

+0

如果我使用存在的JSP文件getPortletContext()。getRequestDispatcher进入它,此工作正常,但在此处我使用默认登录页面,并且它向我抛出此错误。那么请告诉我,如果使用默认登陆页面这种方式是正确的? – Gajjini 2012-04-10 10:09:04

+0

@ user1318607在日志中有什么有趣的地方? – soulcheck 2012-04-11 10:44:21

回答

2

这个外部链接根据PortletContext.getRequestDispatcher()的jsr168和jsr286文档,

路径名必须以斜杠(/)开头,并被解释为相对于当前上下文根的 。

因此使用"http://localhost:8086/user/test/home"作为参数是错误的。

你可能想要做的是重定向。在Portlet环境中,您只能在动作请求中使用ActionResponse.sendRedirect(String)

+0

我会使用ActionResponse,所以这里的字符串值应该是/ user/test/home?那是对的吗 ? – Gajjini 2012-04-10 15:13:39

+0

@ user1318607如果使用actionResponse,则可以使用'http:// localhost:8086/user/test/home'。关键是你不应该(也不能)在'doView()'中做重定向。 – soulcheck 2012-04-10 15:15:08

+0

我已更新我的问题,请参阅此问题。 – Gajjini 2012-04-10 17:31:52

相关问题