struts2 ignore particular pattern

…衆ロ難τιáo~ 提交于 2019-11-30 19:07:38

问题


I am using strust2 for my web application development. My struts.xml file will be like:

<!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>

and my web.xml file will be something like:

<?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>

and now, if i access like: http://localhost:8080/appName/ its going to my signup action perfectly. But when i tried to access like http://localhost:8080/appName/checking (for webservices), Its even looking in struts.xml and getting an error message like:

HTTP Status 404 - There is no Action mapped for namespace / and action name checking... even after defining this in web.xml..

Is there any way to exclude a pattern in struts2, so that when I hit http://localhost:8080/appName/checking, it must not look struts action, it must call my default page path defined in web.xml file.

Thanks..


回答1:


you can probably add exclude pattern in your struts.xml, something like

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

read here and find excludePattern for more information.




回答2:


this could works:

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

an action exampe:




回答3:


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

the constant excludePattern explicit exclusions (since 2.1.7)



来源:https://stackoverflow.com/questions/8191957/struts2-ignore-particular-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!