<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
   </filter>

    <filter-mapping> 
      <filter-name>struts2</filter-name> 
      <url-pattern>*.action</url-pattern> 
    </filter-mapping>
    <filter-mapping> 
      <filter-name>struts2</filter-name> 
      <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
<url-pattern>*.action</url-pattern>  这怎么不能改成 比如 <url-pattern>aaa.action</url-pattern>   只过滤 aaa.action 这样不行出错,有没有什么办法能这样<url-pattern>aaa.action</url-pattern><url-pattern>*.action</url-pattern> aaa.action这样可以 改成 <url-pattern>*.paln</url-pattern> aaa.paln 这样出404什么原因啊

解决方案 »

  1.   

    struts2过滤器的拦截就是/*,这个路径不要随便改, 否则你很多东西都访问不到的, 比如struts标签,很多静态资源等.!
    要改后缀修改配置文件的常量.!    你的意思是,,你用个struts2,就只为过滤一个action.? 我不太明白你这样做的意义是什么喔!
      

  2.   

    404那是因为struts2不认.plan的后缀名, 你要想让它认你的后缀名, 可以修改这个常量
    struts.action.extension
      

  3.   

    struts2跟struts1是两回事, 不要认为struts1的配置方法在struts2里面也管用
      

  4.   

    struts.xml里面
    配置<constant name="struts.action.extension" value="你要的后缀名,如有多个以逗号隔开">
      

  5.   

    在你的struts.xml裏面添加<constan name="struts.action.extension" value="action"></constan>
      

  6.   

    或者你在web.xml里面配置init-param也行!
      

  7.   


    不行哦2010-06-18 15:38:05 [com.opensymphony.xwork2.util.DomHelper]-[ERROR] Element type "constan" must be declared. at (null:20:58)
    org.xml.sax.SAXParseException: Element type "constan" must be declared.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)struts.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>
    <constant name="struts.i18n.encoding" value="GBK" />
    <constant name="struts.ui.theme" value="simple" />
    <constant name="struts.devMode" value="false" />
    <constan name="struts.action.extension" value="action"></constan>
    <include file="struts-default.xml" />
    <package name="testDemoAction" extends="struts-default">
          <action name="testDemoAction" class="com.haizone.struts.action.test.TestDemoAction">
             <result name="select">/test/select.jsp</result>
             <result name="checkbox">/test/checkbox.jsp</result>
           </action>
    </package> <package name="struts2" extends="struts-default">
    <interceptors> <interceptor name="authority"
    class="com.haizone.interceptors.AuthInterceptor" />
    <interceptor-stack name="mydefault"> <interceptor-ref name="defaultStack" /> <interceptor-ref name="authority" /> </interceptor-stack> </interceptors> <default-interceptor-ref name="mydefault" />
    <global-results>
    <result name="error">/commons/error.jsp</result>
    <result name="errorTip">/commons/errorTip.jsp</result>
    <result name="no_auth">/commons/no_auth.jsp</result>
    <result name="fieldError">/commons/fieldError.jsp</result>
    <result name="login">/jsp/home/login.jsp</result>
    </global-results>
    <!--  
    <global-exception-mappings>
    <exception-mapping result="global"
    exception="java.sql.SQLException">
    </exception-mapping>
    <exception-mapping result="businessError"
    exception="com.haizone.util.BusinessException">
    </exception-mapping>
    <exception-mapping result="error"
    exception="java.lang.Exception">
    </exception-mapping>/jsp/clientManager/myShop/uploadResponse.jsp
    </global-exception-mappings>-->   <action name="myUpload" class="com.haizone.struts.commons.UploadAction">
    <interceptor-ref name="fileUpload">
    <param name="allowedTypes">
    image/bmp,image/png,image/gif,image/pjpeg,image/jpg,image/JPG,image/jpeg,application/vnd.ms-excel,video/quicktime,video/x-msvideo
    </param> 
    <param name="maximumSize">3000009715</param>
    </interceptor-ref>
    <interceptor-ref name="defaultStack" />
    <result name="input">/commons/upload.jsp</result>
    <result name="success">/commons/showUpload.jsp</result>
    </action>
       <action name="client" class="com.haizone.struts.action.test.Client">
    <interceptor-ref name="fileUpload">
    <param name="allowedTypes">
    image/bmp,image/png,image/gif,image/pjpeg,image/jpg,image/JPG,image/jpeg,video/quicktime,video/x-msvideo
    </param> 
    <param name="maximumSize">3000009715</param>
    </interceptor-ref>
    <interceptor-ref name="defaultStack" />
    <result name="input">/commons/uploadClientDemo.jsp</result>
    <result name="success">/commons/showUpload.jsp</result>
    </action>   
    </package>
    <include file="struts_xml/struts_auth.xml"></include>
    <include file="struts_xml/struts_education.xml"></include>
    <include file="struts_xml/struts_resource.xml"></include>
    <include file="struts_xml/struts_gear.xml"></include>
    <include file="struts_xml/struts_plan.xml"></include>
    <include file="struts_xml/struts.xml"></include>
    <include file="struts_xml/struts_basedata.xml"></include>
    <include file="struts_xml/struts_policemange.xml"></include>  
    <include file="struts_xml/struts_interior.xml"></include>  
    <include file="struts_xml/struts_service.xml"></include>  
    <include file="com/hizone/workflow/config/struts_workflow.xml"></include>   
    </struts>
    这样出错
      

  8.   

    <constan name="struts.action.extension" value="action"></constan>
    T
      

  9.   

    struts1.x 和struts2.x的差别太大了 不能照搬
      

  10.   

    struts.xml<constant name="struts.action.extension" value="action,aaa"></constant>web.xml<filter-mapping> 
          <filter-name>struts2</filter-name> 
           <url-pattern>*.action</url-pattern> 
           <url-pattern>*.aaa</url-pattern> 
        </filter-mapping>还是不行......
    window.location.href="<%=pagepath %>/resource/addrequest.aaa 这样还是出404 
    window.location.href="<%=pagepath %>/resource/addrequest.action 这样可以
      

  11.   

    web.xml中配置一个就行了.  拦截/*
      

  12.   

    <filter-mapping> 
          <filter-name>struts2</filter-name> 
           <url-pattern>/*</url-pattern>
        </filter-mapping>
    后缀名的事情过滤器会帮你处理
      

  13.   

    你把它们在WEB.xml中分别做映射试试也就是用俩个fliter-mapping
      

  14.   


    /*  我试了 .aaa不行  .action可以
      

  15.   

    请问下你修改了struts.xml后有没有重部署喔
      

  16.   

    那你修改struts.properties试试,后者在struts.xml中<constant name="struts.action.extension" value="do,action" />value值注意顺序,action在后面
      

  17.   

    哦是这样的<constant name="struts.action.extension" value=",do,action" ></constant>
      

  18.   


    struts.properties怎么修改 
    我的是这样的struts.objectFactory = spring
    struts.locale = zh_CN
    struts.i18n.encoding = GBK
    struts.enable.DynamicMethodInvocation = true
    struts.i18n.reload = truestruts.custom.i18n.resources = globalMessages_zh_CN
    struts.multipart.saveDir = /tmp 
    struts.multipart.maxSize=3000009715
    struts.action.extension=action我加了个
    struts.action.extension=aaa 整个都不行了 - -!
      

  19.   

    还是配置struts.xml吧,<constant name="struts.action.extension" value=",do,action" ></constant>注意那个逗号
      

  20.   

    你不早说你有struts.properties.?
    struts.properties里面配置的常量优先struts.xml,
    常量只需要配置一个地方就可以了.!
    如果你是在struts.properties中配的
    在你的struts.properties中写
    struts.action.extension=action,aaa
    配置多个扩展名
      

  21.   

    好的我试试
     我把struts.action.extension=action,aaa这句删了可以
      

  22.   

    自定义一个过滤器 在web.xml里增加一个栏位申明这个过滤器 并注入一些参数(要过滤的action名,可以使用符号隔开),然后在过滤器里判断请求的url 如果涵括web.xml里的要过滤的action 则做指定操作。