公司是做C/S应用的,分为普通java工程的前台和web工程的后台。
最近我做了一个B/S架构的应用,使用Spring+struts2+JPA,现在老大要求我将这个应用整合到以前的c/s架构的service里面,现在问题是: 我只想用struts2处理所有以Action结尾的Bean和*.jsp页面,其他都不处理。 我该如何实现啊?  web.xml里面不能使用/*的,否则会处理所有请求,以前的c/s程序就用不起了
如:
web.xml:
错误1:
<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>
  </filter-mapping>这样的话C/S程序要报错的,我该如何实现呢?错误2:
<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>*.action</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.jsp</url-pattern>
  </filter-mapping>错误3:
<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <servlet-name>*.action,*.jsp</servlet-name>
  </filter-mapping>请问还有其他实现方式么?struts2web.xmlc/sfilter

解决方案 »

  1.   

    <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>/*.action</url-pattern>
      </filter-mapping>
      <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*.jsp</url-pattern>
      </filter-mapping>
    你确定需要这样配置?你把jsp过滤掉了,可能会有问题的
      

  2.   

    <url-pattern>/*.action</url-pattern>
    <url-pattern>/*.jsp</url-pattern>
    应该这样就可以了吧。
      

  3.   

    补充一下: 
    <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>
       </filter-mapping>
    这样配置的话,所有的jsp页面是可以访问的,但是以前的C/S程序就不能用了---谢谢 trocp  但是这样还不行的
    ---谢谢 huanlin08   这样也不行啊
    ---谢谢 u010111184 这个也不行的球解答啊
      

  4.   

    目录结构如下:
    web.xml的配置:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>lisService_v2</display-name>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
        <!--<welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
       
        
      --></welcome-file-list>
      <listener>
        <listener-class>app.core.config.CdxtLisContextLoaderListener</listener-class>
       <!--  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> -->
      </listener>
      
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
                /WEB-INF/applicationContext.xml
            </param-value>
      </context-param>
      
      <context-param>
       <param-name>org.mule.config</param-name> 
       <param-value>mule-config.xml</param-value>
    </context-param> 
     <!-- <listener> 
       <listener-class>org.mule.config.builders.MuleXmlBuilderContextListener
         </listener-class> 
    </listener>  -->  <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>
               org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>/WEB-INF/service-config.xml</param-value>
        </init-param>
      </servlet>
      
     
         
         
      <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/service/*</url-pattern>
      </servlet-mapping>
      <filter>
        <filter-name>character</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
          <param-name>encoding</param-name>
          <param-value>utf8</param-value>
        </init-param>
        <init-param>
          <param-name>forceEncoding</param-name>
          <param-value>true</param-value>
        </init-param>
      </filter>
      <filter-mapping>
        <filter-name>character</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
    <!-- struts的配置,负责lis的web应用 -->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    <!--     <init-param>  
            <param-name>actionPackages</param-name>  
            <param-value>app.lisWebFunction.login,app.lisWebFunction.sample.action</param-value>  
        </init-param>  -->
      </filter>
      <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping> 
    </web-app>struts.xml里面的配置: 
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd"><struts>
    <!-- <constant name="struts.action.extension" value="action,jsp,"></constant> -->
        <package name="default" namespace="/sample" extends="struts-default">
    <!-- 登录界面 -->
            <action name="login" class="app.lisWebFunction.login.LoginAction">
                <result name="success">welcome.jsp</result>
    <result name="error" type="redirect">../index.jsp</result>
            </action>
            <!-- 1.样本查询界面 -->
            <action name="sampleQueryResult" class="app.lisWebFunction.sample.action.SampleQueryResultAction">
                <result name="success">sampleQuery.jsp</result>
    <result name="error">fail.jsp</result>
            </action>
            <!-- 2.样本统计界面 -->
             <action name="sampleStatistics" class="app.lisWebFunction.sample.action.SampleStatisticsResultAction">
                <result name="success">sampleStatistics.jsp</result>
    <result name="error">fail.jsp</result>
            </action>
             <!-- 3.样本明细统计界面 -->
            <action name="sampleStatisticsDetail" class="app.lisWebFunction.sample.action.SampleStatisticsDetailResultAction">
                <result name="success">sampleStatisticsDetail.jsp</result>
    <result name="error">fail.jsp</result>
            </action>
            <action name="lis" class="app.lisWebFunction.sample.action.SampleStatisticsResultAction">
                <result name="success">welcome.jsp</result>
    <result name="error" type="redirect">../index.jsp</result>
            </action>
        </package>
    </struts>
      

  5.   

    对了  以前C/S程序运行的时候,会访问http://localhost:8080/lisService/service/lis,所以才导致了现在的一系列问题。前台访问后台,是通过这种方式的:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    >
     
        <bean id="Service" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
            <property name="serviceUrl">
                <value>http://localhost:8080/lisService/service/lis<value>
            </property>
            <property name="serviceInterface" value="app.manager.api.Service"/>
        </bean>    
         
    </beans>
      

  6.   

    终于找到解决方案了谢谢各位兄弟了
    解决方法就是:
    在struts.properties文件里面添加一个变量:
    struts.action.excludePattern=/service/.*
    这样的话,所有service请求都不处理了