我现在遇到一个问题:
在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");
}
}
在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");
}
}
解决方案 »
- 哪位大仙帮我看一下,为什么在jsp中无法实例化一个类
- 招标哦,急求大神帮忙啊!!
- struts2 画面传递中文参数乱码!!!
- 求学习Structs的学习资料,望给予指点!!
- 文件下载的文件名问题
- Eclipse中的tomcat启动问题
- 运行wen.class时,错误:Exception in thread "main" java.lang.NoClassDefFoundError:wen
- soupUI调用webService报错,请指教
- 急急急,在线等待,ArrayList和Vector的区别,HashMap和Hashtable的区别
- 无法打包bean(在线等待)
- HttpSessionBindingListener的问题,困惑啊!!
- 在ie 6.0.2900版本上,如何设置cookie的可用性?
================
下一行加上System.out.println("test");还有就是struts-config.xml文件确实配了吗
还有有注释掉execute方法吧
但是结果为null."你在show.jsp中得到结果为null,请问你是通过URL直接访问show.jsp的?还是通过DispatchAction转发的?如果是经过DispatchAction转发的,那说明Struts转发环节没有问题,只是往容器赋值或取值是有错,你可以这样测试:
在"request.setAttribute("msg","my msg");"后
加这样的测试语句:request.getAttribute("msg);
然后看命令行输出的值是否正确.
在页面还可以用<prisent>判断是否存在request.getAttribute("msg").