尝试将用户重定向到登录页面,如果他们的会话在我编写的processPreProcess覆盖中不再有效。我用过两个
response.sendRedirect("launch.do?method=launchLogin&type=multi");
和
ActionMapping loginMapping = processMapping(request, response, "/launch");
ActionForward loginForward = loginMapping.findForward("launchLogon");
processForwardConfig(request, response, loginForward);
我可以看到正在调用的正确登录操作,并且它成功转发到正确的页面,但我的表单值由于某种原因没有传递给JSP。我在动作中设置了表单值,如下所示:
if (type !=null && type.equals("multi")){
Collection<OptionBean> list = this.loadApplicationDropDown();
if (list != null) {
theForm.setApplicationList(list);
theForm.setShowDropDown(true);
}
}
return mapping.findForward("Success");
我可以看到正在运行此代码并且这些成员正确填充但是一旦它到达JSP,applicationList就为空,showDropDown为false。我也知道Action类正常工作,因为如果我正常启动应用程序,表单会显示填充下拉元素。
我还需要做些什么来确保我的ActionForm在范围内吗?
修改 这是jsp上的相关代码。我使用bean:write来检查showDropDown的值,即使在操作中将其设置为true,它也会返回false。 applicationList在遇到jsp时也是空的,但是我再次看到它被填充了:
<logic:present property="applicationList" name="logonForm">
<logic:equal property="showDropDown" name="logonForm" value="true">
<tr>
<td class="lbl" align="left">
<html:select property="application" size="1">
<html:optionsCollection name="logonForm" property="applicationList" value="value" label="label"/>
</html:select>
</td>
</TR>
</logic:equal>
</logic:present>
修改 这是动作映射定义:
action path="/launch"
type="otrack.core.LaunchApplicationAction"
parameter="method"
name="logonForm"
scope="request"
input="/jsp/index.jsp">
<forward name="launchLogon" path="/launch.do?method=launchLogin&type=multi"/>
<forward name="Success" path="/jsp/Logon.jsp"/>
<forward name="Launch" path="/jsp/appFrameNew.jsp"/>
<forward name="Failure" path="/jsp/index.jsp"/>
</action>
以下是Action类中的完整方法:
public ActionForward launchLogin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
LogonForm theForm = (LogonForm) form;
ActionErrors errors = new ActionErrors();
try {
//get the request parameter name "type" to know if
//drop down needs to be shown or not
String type = request.getParameter("type");
if (type !=null && type.equals("multi")){
Collection<OptionBean> list = this.loadApplicationDropDown();
if (list != null) {
//set the option list on the form
theForm.setApplicationList(list);
theForm.setShowDropDown(true);
}
}
HttpSession session = request.getSession(false);
return mapping.findForward("Success");
} catch (Exception e) {
if (e instanceof AppException) {
AppException ae = (AppException) e;
if (ae.getRootCause() != null) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError(ae.getMessage().trim(), ae.getRootCause().getMessage()));
} else {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError(ae.getMessage().trim(), ""));
}
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
}
return (new ActionForward("Failure"));
}
}