struts2忽略特定模式

时间:2011-11-19 04:42:36

标签: struts2 struts2-namespace

我正在使用strust2进行Web应用程序开发。我的struts.xml文件将是:

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

<struts>
    <package name="default" extends="struts-default" namespace ="/">
        <action name="signup">
            <result>/check.jsp</result>
        </action>
    </package>
</struts>

我的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>sample</display-name>  
  <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>

  <servlet>
    <servlet-name>My WS</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>com.dr1.dr2</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>My WS</servlet-name>
    <url-pattern>/checking</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

现在, 如果我访问:http://localhost:8080/appName/它完全符合我的注册操作。 但是,当我尝试访问类似http://localhost:8080/appName/checking(对于webservices)时,它甚至查看struts.xml并收到如下错误消息:

HTTP状态404 - 没有针对命名空间/和操作名称检查映射的操作。 .. 甚至在web.xml中定义它之后..

有没有办法排除struts2中的模式,所以当我点击http://localhost:8080/appName/checking时,它一定不能看struts动作,它必须调用我在web中定义的默认页面路径。 xml文件。

谢谢..

3 个答案:

答案 0 :(得分:5)

你可以在struts.xml中添加排除模式,比如

<struts>
    <constant name="struts.action.excludePattern" value="appName/checking"/>
</struts>

阅读here并找到excludePattern以获取更多信息。

答案 1 :(得分:1)

这可能有效:

     <!-- exclude pattern -->  
 <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/struts/*</url-pattern>
</filter-mapping>

动作示例:                        

答案 2 :(得分:0)

<constant name="struts.action.excludePattern" value="appName/checking"/>

常量excludePattern显式排除(自2.1.7起)