让地址栏显示返回实际jsp的的实际位置

来源:互联网 发布:有什么聊天软件 编辑:程序博客网 时间:2024/05/17 22:02

比如在工程中struts.xml中有如下配置:

[html] view plain copy
  1. <action name="login" class="test.user" method="login">  
  2.     <result name="input">/index.jsp</result>  
  3. </action>  

所有网页工程中,指向login的action,处理完之后,地址栏会显示http://localhost:8080/某某工程/login。


而不是http://localhost:8080/某某工程/index.jsp,这对于浏览者或者在调试中再次刷新页面,极其不方便,我们更多地,是习惯如下的效果:


此时,只需要在<result>中加入type="redirect"这个属性即可,比如上述的配置,更变成如下即可:

[html] view plain copy
  1. <action name="login" class="test.user" method="login">  
  2.     <result name="input" type="redirect">/index.jsp</result>  
  3. </action>  

如下图所示:



在tomcat中,如果web-inf/jsp/xxx.jsp无权限访问

那么在上图<result name="input" type="redirect">/index.jsp</result>

可以改为<result name="input" type="redirect">/xxx.do</result>

其中xxx.do为struts.xml里配置的action,这个action将定位到你想要访问的/index.jsp.