关于网友提出的“ [Struts]关于DispatchAction中的request问题”问题疑问,本网通过在网上对“ [Struts]关于DispatchAction中的request问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: [Struts]关于DispatchAction中的request问题描述:
我现在遇到一个问题:
在DispatchAction中我有一个方法saveBook(),它有个参数request,我要在该方法中调用request.setAttribute("msg","my msg")
然后forward到另外一个页面show.jsp
在show.jsp中,我用out.println(request.getAttribute("msg"))打印出我想要的信息my msg.
但是结果为null.
我想这个应该是个生命周期的问题.我用Action就不存在这个问题。请高手指教!
相关代码:
public class TestAction extends DispatchAction {
public ActionForward ok(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
TestForm testForm = (TestForm) form;
request.setAttribute("msg","my msg");
return mapping.findForward("ok");
}
}