先上关键代码:
struts.xml文件内容: <package name="default" namespace="/" extends="struts-default"> <action name="index" class="actionclass.contral">
<result name="myindex">
/myindex.jsp
</result>
</action>
</package>contral.java文件内容:package actionclass;public class contral {
public String execute(){
return "myindex";
}
}问题:我本意是访问http://localhost:8080/study0809/index,然后找到index所在action,然后调用我自己写的类actionclass.contral,然后返回myindex字符串,然后根据result配置的节点,然后跳转到myindex.jsp.但是我访问的时候页面无法跳转到myindex.jsp,而是跳转到其他页面了
struts.xml文件内容: <package name="default" namespace="/" extends="struts-default"> <action name="index" class="actionclass.contral">
<result name="myindex">
/myindex.jsp
</result>
</action>
</package>contral.java文件内容:package actionclass;public class contral {
public String execute(){
return "myindex";
}
}问题:我本意是访问http://localhost:8080/study0809/index,然后找到index所在action,然后调用我自己写的类actionclass.contral,然后返回myindex字符串,然后根据result配置的节点,然后跳转到myindex.jsp.但是我访问的时候页面无法跳转到myindex.jsp,而是跳转到其他页面了
检查result是否为myindex.jsp会不会有拦截器啥的改变了result。
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>,跳转到了index.jsp页面
public String execute(){
return "myindex";
}那么就是这个没有执行啊。你要是直接访问:http://localhost:8080/study0809/index.jsp或者是直接访问:http://localhost:8080/study0809/他都会自动显示web.xml中那个index.jsp页面。你要是访问:http://localhost:8080/study0809/index.action那么就会去寻找index.action。从而执行actionclass.contral里面的execute方法啊。
还有就是 execute()方法的返回值 默认的是 “success”。 LZ 如果你改了相应的配置的话,那么就应该没什么问题了。你……
struts action要这样配置才行:<!-- 转到你的页 -->
<result name="myindex" type="redirectAction">myindex.jsp</result>
http://wanggp.iteye.com/blog/663701