Liferay:如何在Liferay中使用RequestDispatcher重定向到公共页面

Liferay:如何在Liferay中使用RequestDispatcher重定向到公共页面,liferay,liferay-6,Liferay,Liferay 6,我已经定义了一个由六个portlet组成的页面,并在portal-ext.properties文件中将其配置为我的默认输入页面 我有一个自定义的登录页面用于联系我的数据库,一旦用户有效,我将使用/user/test/home将他重定向到此页面,并尝试使用http://localhost:8086/user/test/home 但这并没有起作用,我继续努力 public void doView(RenderRequest请求、RenderResponse响应) 抛出PortletException

我已经定义了一个由六个portlet组成的页面,并在
portal-ext.properties
文件中将其配置为我的默认输入页面

我有一个自定义的登录页面用于联系我的数据库,一旦用户有效,我将使用/user/test/home将他重定向到此页面,并尝试使用
http://localhost:8086/user/test/home

但这并没有起作用,我继续努力

public void doView(RenderRequest请求、RenderResponse响应)
抛出PortletException,IOException{
response.setContentType(“text/html”);
System.out.println(“doView方法内部”);
PortletRequestDispatcher=null;
if(this.name.isEmpty()){
dispatcher=getPortletContext().getRequestDispatcher(
“/WEB-INF/jsp/AllInOne_view.jsp”);
}否则{
request.setAttribute(“name”,this.name);
dispatcher=getPortletContext().getRequestDispatcher(
"http://localhost:8086/user/test/home");
}
this.name=“”;
这是“行动”;
调度器。包括(请求、响应);
}
17:53:47765错误[render_portlet_jsp:154]java.lang.NullPointerException
访问org.ravi.learning.AllInOne.doView(AllInOne.java:57)
位于javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328)
位于javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
在com.liferay.portlet.FilterChainImpl.doFilter上(FilterChainImpl.java:100)
位于com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
位于com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:93)
位于javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
位于org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
java是我的定制GenericPortlet类AllinOne.java:57是

dispatcher.include(请求、响应);
此处更新部分

这是java类

package org.ravi.learning;
导入java.io.IOException;
导入javax.portlet.ActionRequest;
导入javax.portlet.ActionResponse;
导入javax.portlet.GenericPortlet;
导入javax.portlet.PortletException;
导入javax.portlet.PortletRequestDispatcher;
导入javax.portlet.RenderRequest;
导入javax.portlet.RenderResponse;
公共类AllInOne扩展了GenericPortlet{
字符串动作=”;
字符串名称=”;
public void processAction(ActionRequest请求、ActionResponse响应)
抛出PortletException,IOException{
System.out.println(“进程内操作方法新”);
this.action=request.getParameter(“myAction”);
如果(此作用等于(“形成”)){
this.name=request.getParameter(“personName”);
}
字符串URL路径=”http://localhost:8086/user/test/home";
sendRedirect(URL路径);
}
公共视图(RenderRequest请求、RenderResponse响应)
抛出PortletException,IOException{
response.setContentType(“text/html”);
}
}
作为一个新用户,我不能发布图片,所以请参考此图片的外部链接


根据PortletContext.getRequestDispatcher()的jsr168和jsr286文档

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

所以使用
”http://localhost:8086/user/test/home“
as参数错误


您可能想做的是重定向。在portlet环境中,您只能在action请求中使用
ActionResponse.sendRedirect(String)

getPortletContext()是否返回对象?只需打印并查看它返回的内容如果我在其中使用现有JSP文件getPortletContext().getRequestDispatcher,这可以正常工作,但这里我使用的是默认登录页,它会引发此错误。因此,请告诉我以这种方式使用默认登录页是否正确???@user1318607日志中有什么有趣的内容吗?我将使用ActionResponse,所以这里的字符串值应该是/user/test/home??对吗?@user1318607如果使用actionResponse,则可以使用
http://localhost:8086/user/test/home
。关键是您不应该(也不能)在
doView()
中执行重定向。