Java Struts 1 processPreProcess方法中的重定向
如果用户的会话在我编写的processPreProcess覆盖中不再有效,则尝试将用户重定向到登录页面。我两者都用过Java Struts 1 processPreProcess方法中的重定向,java,struts,Java,Struts,如果用户的会话在我编写的processPreProcess覆盖中不再有效,则尝试将用户重定向到登录页面。我两者都用过 response.sendRedirect("launch.do?method=launchLogin&type=multi"); 及 我可以看到调用了正确的登录操作,并且它成功地转发到了正确的页面,但是由于某种原因,我的表单值没有被传递到JSP。我在动作中设置表单值,如下所示: if (type !=null && type.equals("multi
response.sendRedirect("launch.do?method=launchLogin&type=multi");
及
我可以看到调用了正确的登录操作,并且它成功地转发到了正确的页面,但是由于某种原因,我的表单值没有被传递到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");
if(type!=null&&type.equals(“多”)){
集合列表=this.loadApplicationDropDown();
如果(列表!=null){
form.setApplicationList(列表);
格式设置显示下拉列表(true);
}
}
返回映射。findForward(“成功”);
我可以看到这段代码正在运行,这些成员得到了正确的填充,但一旦它进入JSP,applicationList为空,showDropDown为false。我还知道Action类工作正常,因为如果我正常启动应用程序,表单会显示,并填充下拉元素
我还需要做些什么来确保我的ActionForm在范围内吗
编辑:
下面是jsp上的相关代码。我使用bean:write来检查showDropDown的值,它返回false,即使它在操作中被设置为true。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 path=“/launch”
type=“otrack.core.LaunchApplicationAction”
参数=“方法”
name=“logonForm”
scope=“请求”
input=“/jsp/index.jsp”>
下面是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"));
}
}
公共ActionForward启动登录(ActionMapping映射、ActionForm表单、,
HttpServletRequest请求,HttpServletResponse响应)
抛出IOException、ServletException{
LogonForm theForm=(LogonForm)表单;
ActionErrors=新的ActionErrors();
试一试{
//获取请求参数名称“type”以了解
//下拉列表是否需要显示
字符串类型=request.getParameter(“类型”);
if(type!=null&&type.equals(“多”)){
集合列表=this.loadApplicationDropDown();
如果(列表!=null){
//在表单上设置选项列表
form.setApplicationList(列表);
格式设置显示下拉列表(true);
}
}
HttpSession session=request.getSession(false);
返回映射。findForward(“成功”);
}捕获(例外e){
如果(例如AppException的实例){
AppException ae=(AppException)e;
如果(ae.getRootCause()!=null){
errors.add(ActionErrors.GLOBAL_ERROR,
新操作错误(ae.getMessage().trim(),ae.getRootCause().getMessage());
}否则{
errors.add(ActionErrors.GLOBAL_ERROR,
新操作错误(ae.getMessage().trim(),“”);
}
保存错误(请求、错误);
return(newactionforward(mapping.getInput());
}
返回(新动作转发(“失败”);
}
}
如果使用
sendRedirect
请求属性将不会被保留,因为它是一个新请求。如果转发是一个重定向
转发,同样的事情。如果表单是会话范围的,那么这无关紧要。没有进一步的信息,很难帮助你。嗯……看起来你说的似乎不是真的发生了什么,而且它以某种方式保留了原始请求的形式。重定向将转到与最初请求的完全不同的操作,因此我不一定希望保留请求属性。我可以看到调用了/launch操作并填充了表单,但这似乎不是响应的一部分,因为jsp没有填充成员。您不会显示如何检索值,但无论哪种方式,您都会在URL中传递值——它们将被封送到表单中,但其他内容都不会。如果需要更好的帮助,您可能需要澄清您的问题并填写一些详细信息。编辑以显示如何检索值。奇怪的是,我可以看到调用了正确的操作,并根据URL中传递的请求参数填充了表单,但当它碰到jsp时,就好像表单根本没有实例化一样。如果有任何其他细节,将是有益的,我会很高兴地张贴。我不确定在这一点上还有什么会有帮助。操作和转发配置有问题。
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"));
}
}