zoukankan      html  css  js  c++  java
  • struts2中<jsp:forward>跳转时报404错误的问题

    index.jsp页面:  
      <jsp:forward page="show.action"></jsp:forward>  
      
    在struts.xml配置如下:  
      <package name="struts2" extends="struts-dafult">  
      <action name="show" class="action.ShowAction">  
        <result name="showinfo">/showinfo.jsp</result>  
      </action>  
      </package>  
    在运行时出现404错误(找不到 show.action )

    问题原因:

    struts2拦截器把forward这个请求拦截了。

    解决方法一:

    修改web.xml文件

     <filter>  
    <span style="white-space:pre">    </span><filter-name>struts2</filter-name>  
    <span style="white-space:pre">    </span><filter-class>  
    <span style="white-space:pre">    </span>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
    <span style="white-space:pre">    </span></filter-class>  
      </filter>  
      <filter-mapping>    
      <filter-name>struts2</filter-name>  
      <url-pattern>/*</url-pattern>  
      </filter-mapping>  
      
      
    修改为:  
      <filter>  
        <filter-name>struts2</filter-name>  
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
        </filter-class>  
      </filter>  
      <filter-mapping>    
        <filter-name>struts2</filter-name>  
        <url-pattern>/*</url-pattern>  
        <dispatcher>INCLUDE</dispatcher>    //增加对<jsp:include page="xxx.action"/>及其<s:include value="xxx.action"/>支持  
        <dispatcher>REQUEST</dispatcher>  
        <dispatcher>FORWARD</dispatcher>  
      </filter-mapping> 

    解决方法二:

    用javascript解决,让请求执行到页面时,接着执行如下的代码,发现页面需要重载,然后就重新发送请求REQUEST,这样当然就会被过滤器所截获到了。

    <script language="javascript">location.replace(URL)</script>

    解决方法三:
    利用html meta,等于也是让页面等待零秒刷新页面,重新发送请求,达到目的。

    <meta http-equiv="refresh" content="0;URL=xxx.action">  
  • 相关阅读:
    Unix命令大全
    vs2008 与 IE8出现的兼容性问题
    Java 创建文件、文件夹以及临时文件
    如何修改Wamp中mysql默认空密码
    PAT 乙级真题 1003.数素数
    Tags support in htmlText flash as3
    DelphiXE4 FireMonkey 试玩记录,开发IOS应用 还是移植
    10 Great iphone App Review sites to Promote your Apps!
    HTML tags in textfield
    Delphi XE4 IOS 开发, "No eligible applications were found“
  • 原文地址:https://www.cnblogs.com/wangkang0320/p/8675746.html
Copyright © 2011-2022 走看看