struts2中的页面跳转问题

sxwxd626 2011-08-10 11:12:04
先上关键代码:
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,而是跳转到其他页面了
...全文
201 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
underhiswing 2011-08-10
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 luciferoffans 的回复:]

既然是跳转到其他页面了,
public String execute(){
return "myindex";
}那么就是这个没有执行啊。

你要是直接访问:http://localhost:8080/study0809/index.jsp或者是直接访问:http://localhost:8080/study0809/他都会自动显示web.xml中那个index.jsp页面。
[/Quote]

还有就是 execute()方法的返回值 默认的是 “success”。 LZ 如果你改了相应的配置的话,那么就应该没什么问题了。

你……
Luciferoffans 2011-08-10
  • 打赏
  • 举报
回复
既然是跳转到其他页面了,
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方法啊。
  • 打赏
  • 举报
回复
故意写错的配置看看?比如action名,然后重启tomcat
zl3450341 2011-08-10
  • 打赏
  • 举报
回复
1。你确定,发请求的时候,请入到你定义的方法没有? 断点,或者写个打印语句就行
sxwxd626 2011-08-10
  • 打赏
  • 举报
回复
跳转到了默认页面,也就是web.xml文件中的<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>,跳转到了index.jsp页面[Quote=引用 1 楼 softroad 的回复:]
LZ代码貌似没错,其他页面名字是啥,搜搜配置文件。看看对应的result。
检查result是否为myindex.jsp会不会有拦截器啥的改变了result。
[/Quote]
wct357110558 2011-08-10
  • 打赏
  • 举报
回复
其他地方有没有设置跳转的啊
magiccxj 2011-08-10
  • 打赏
  • 举报
回复
web.xml中,有个welcome-file-list的节点,lz去看看
softroad 2011-08-10
  • 打赏
  • 举报
回复
LZ代码貌似没错,其他页面名字是啥,搜搜配置文件。看看对应的result。
检查result是否为myindex.jsp会不会有拦截器啥的改变了result。
sxwxd626 2011-08-10
  • 打赏
  • 举报
回复
问题解决了,我把myeclipse关了,然后重新打开,然后就一切就正常了,应该是BUG,讨厌BUG
love452076852 2011-08-10
  • 打赏
  • 举报
回复
看看Action默认后缀
lost_guy_in_scut 2011-08-10
  • 打赏
  • 举报
回复
打断点看看吧,看有没进入你的action方法。没有的话就看看配置是不是那里配错了。
underhiswing 2011-08-10
  • 打赏
  • 举报
回复
10楼的 type根本不用填,默认的就是dispatcher !!
sweat89 2011-08-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 iuprg 的回复:]

楼上的回答都不对!
struts action要这样配置才行:

<!-- 转到你的页 -->
<result name="myindex" type="redirectAction">myindex.jsp</result>
[/Quote]
没必要填type,默认的就行了吧
  • 打赏
  • 举报
回复
详细 可以参考这篇
http://wanggp.iteye.com/blog/663701
  • 打赏
  • 举报
回复
现在 CSDN 越来越堕落了.............
  • 打赏
  • 举报
回复
楼上的回答都不对!
struts action要这样配置才行:

<!-- 转到你的页 -->
<result name="myindex" type="redirectAction">myindex.jsp</result>

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧