首页 > 代码库 > struts2.5.5通配符问题

struts2.5.5通配符问题

问题:使用通配符会报错,找不到action。

问题原因: struts2.5 为了增加安全性,在 struts.xml 添加了这么个属性:<global-allowed-methods>regex:.*</global-allowed-methods>

解决:

一、注意头部信息,这个应该是用来指定文件中允许使用那些标签。

<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd">

 

二、加上:  <global-allowed-methods>regex:.*</global-allowed-methods> 例如:

<!-- 定义一个名为 yh 的包,继承 Struts 2 的默认包 -->
    <package name="yh" extends="struts-default">    
        
        <interceptors><!-- 配置自定义拦截器LoginedCheckInterceptor -->
            <interceptor name="loginedCheck" class="com.yh.core.filter.LoginedCheckInterceptor"/>
        </interceptors>       
             
        <global-results><!-- 定义全局result -->
            <result name="exception">/exception.jsp</result><!-- 定义名为exception的全局result -->
            <result name="tologin">/views/jsp/main/tologin.htm</result>
        </global-results>
        
         
        <global-allowed-methods>regex:.*</global-allowed-methods>
        <global-exception-mappings><!-- 定义全局异常映射 -->
            <!-- 捕捉到Exception异常(所有异常)时跳转到exception所命名的视图上 -->
            <exception-mapping exception="java.lang.Exception" result="exception"/>
        </global-exception-mappings>    
    </package>

 



或者(不加上面这句),在action中加上指定允许调用的方法的语句:
<allowed-methods>login,logout</allowed-methods>

struts2.5.5通配符问题