我也觉得奇怪,所以我在Action.execute() 里面用 mapping.getInputForward();总是跳到一个空白页面去,
后来才发现 mapping.getInputForward() = null, 实在不知道问题出在哪里???
后来才发现 mapping.getInputForward() = null, 实在不知道问题出在哪里???
解决方案 »
- Spring数据源问题
- spring 入门代码调试总是出错
- 请问使用base64加密后如何使用查询和数据库的比对
- tomcat5.5.4如果不连到公网上,启动后就会报错,而且影响到程序运行。
- jbuilder9配置JDBC驱动程序的问题
- windows下安装eclipse的cdt插件,应该怎样运行它的项目呢?
- 请java高手进来,求解java比.net优秀的技术。
- Weblogic7和JBuilder8的一个问题,大虾请进?高分,在线等待!马上结帐。
- 关于ASN1与C++的问题
- 请问,一个手机端应用(非浏览器)访问后端服务,在后端服务如何获取IP地址等信息
- web服务器的选择?有些疑问
- 方框乱码(下拉列表中的label)是怎么生成的?刷新一遍就正常了,太奇怪了。
type="org.apache.struts.webapp.example.TestAction"
name="testForm" scope="session"
input="/testInput.jsp" validate="true">
有execute中直接根据判断来调用mapping.findForward("success");试试..
type="org.apache.struts.webapp.example.TestAction"
name="testForm"
scope="request"
input="testInput">
<forward name="testInput" path="/testInput.jsp"/>
</action>这样是可以的,
我就不知道为什么直接在 input 里面填写 /testInput.jsp,
mapping.getInput() 可以得到 "/testInput.jsp",
但是 mapping.getInputForward() 却总是null???究竟是什么原因呢???在 struts-config_1_1.dtd文档里面也写了
input: Module-relative path of the action or other resource to which control should be returned if a validation error is encountered. 并非一定要是 Module-relative path ,还可以是 other resource 啊,
怎么会不行呢???
还有运行结果???
return当然是有的,
就是 return (mapping.getInputForward());
因为总是跳到一个空白的页面去, 后来打印一下才知道 mapping.getInputForward()=null.其他的代码是无关紧要的, 因为并不影响 mapping.getInputForward()的值,所以没有贴出来.
还是forward写在<global-forwards></global-forwards>中?
不太懂,刚学,
type="org.apache.struts.webapp.example.TestAction"
name="testForm"
scope="request"
input="testInput">
<forward name="testInput" path="/testInput.jsp"/>
</action>这段话本来就没问题,但你在Action中的代码却有错,如下String input = mapping.getInput();
ActionForward forward = mapping.getInputForward(); mapping.getInput()与mapping.getInputForward()得到的是两个不同值
前者取出的是你的input里面的内容,针对这段代码来讲,取出的值是"testInput"
后者取出的是根据你input里面的字符串来查找转向地址,也就是在当前mapping中
<forward name="testInput" path="/testInput.jsp"/>
等类似的转向里查找name值,在这段代码里查找将会匹配到forward name="testInput",而转向其指向的"/testInput.jsp"同样的道理,如果你在input 里写"/testInput.jsp"
那么就应该有类似一句:
<forward name="/testInput.jsp" path="/testInput.jsp"/>
//那么就应该有类似一句:
//<forward name="/testInput.jsp" path="/testInput.jsp"/> 如果我有后面这句 <forward name="/testInput.jsp" path="/testInput.jsp"/>
, 那么, 我就可以在 input 里面写 testInput 了.我想知道: 是不是 input 里面只能填写 后面定义的 <forward name="" path="..."> name 里面的内容? 只在 input 里面写"/testInput.jsp" 这样为什么不行?
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {
String input = mapping.getInput();
ActionForward forward = mapping.findForward("success");
System.out.println(input); //testInput.jsp
System.out.println(forward); //null
}
mapping.getInputForward(); 你的配置文件里有两个forward你没指定那一个啊
我是想知道: 直接在input属性里面指定 "/testInput.jsp" 为什么不行?
-----------------------------------------------------------------input 里面的页面地址本来是在ActionForm里面验证失败时返回的页面
但你在Action中调用到这一句
ActionForward forward = mapping.getInputForward();
所以才会找你forward里面的内容如果
input="/testInput.jsp">
你也可以这样String path = mapping.getInput();
ActionForward forward = new ActionForward();
forward.setPath(request.getContextPath()+path);//因为是JSP,所以要加上下文根
return forward;
应该也能取得同样的效果
看看文档吧:
public ActionForward getInputForward()
Create (if necessary) and return an ActionForward that corresponds to the input property of this Action.
----------
public java.lang.String getInput()
Get the context-relative path of the input form to which control should be returned if a validation error is encountered.