我想通过键入他的个人密钥来验证用户的请求。首先他执行请求,现在portlet重定向到第二个jsp文件,在那里他用密钥验证,最后如果没有,则portlet完成请求,否则返回第一步。
这是代码,
1.- view.jsp(请求)
<%@ include file="/html/blue/init.jsp" %>
Welcome to our Colors workflow
<br/>
<%
PortletURL redirectURL = renderResponse.createActionURL();
redirectURL.setParameter(ActionRequest.ACTION_NAME, "redirect");
%>
<aui:form name="fmAdd" method="POST" action="<%= redirectURL.toString() %>">
<aui:input type="hidden" name="myaction" value="add" />
<aui:button type="submit" value="Add New Box"/>
</aui:form>
<aui:form name="fmList" method="POST" action="<%= redirectURL.toString() %>">
<aui:input type="hidden" name="myaction" value="list" />
<aui:button type="submit" value="Show All Boxes"/>
</aui:form>
2.- java代码,
public void redirect(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String action = ParamUtil.getString(actionRequest, "myaction");
PortletURL redirectURL = null;
String redirectJSP = "/checkuser.jsp";
if(action != null) {
String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
portletName, themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);
redirectURL.setParameter("myaction", action);
redirectURL.setParameter("jspPage", redirectJSP);
}
actionResponse.sendRedirect(redirectURL.toString());
}
3._ checkuser.jsp(用户用他的密钥验证)
<%@ include file="/html/blue/init.jsp" %>
<%
PortletURL checkUserURL = renderResponse.createActionURL();
checkUserURL.setParameter(ActionRequest.ACTION_NAME, "checkUser");
String myaction = renderRequest.getParameter("myaction");
%>
<p> Your action: <%= myaction %> </p>
<aui:form name="fm" method="POST" action="<%= checkUserURL.toString() %>">
<aui:input type="hidden" name="myaction" value="<%= myaction %>" />
<aui:input type="text" name="key" value=""/>
<aui:button type="submit" value="Save"/>
</aui:form>
在这个阶段,我遇到了第一个问题,因为我没有看到请求的值(myaction变量)。这仅适用于调试。
4._捕获最后一个表单的java代码,
public void checkUser(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String key = ParamUtil.getString(actionRequest, "key");
String action = ParamUtil.getString(actionRequest, "myaction");
String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
portletName, themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);
String redirectJSP = "/view.jsp";
if(key != null) {
if(key.equalsIgnoreCase("blue")) {
if(action != null) {
if(action.equalsIgnoreCase("add")) {
redirectJSP = "/update.jsp";
}
if(action.equalsIgnoreCase("list")) {
redirectJSP = "/list.jsp";
}
}
}
}
redirectURL.setParameter("jspPage", redirectJSP);
actionResponse.sendRedirect(redirectURL.toString());
}
在此阶段,portlet始终转到view.jsp,用户执行请求。我认为key和action变量都是null或者至少是其中之一。
我做错了什么?
此致 何
答案 0 :(得分:2)
在Liferay中,参数是使用命名空间设置的,这样当页面上有超过1个portlet时它们不会引起问题。特别是如果你在页面上有两个完全相同的portlet!因此,当您设置myaction
时,它实际上会设置为_myportlet_INSTANCE_xlka_myaction
或类似的东西。
您可以使用com.liferay.portal.kernel.util.ParamUtil
来帮助您获取参数,而无需担心范围界定。例如:
ParamUtil.getString(request, "myaction");