struts2 忽略特定模式 [英] struts2 ignore particular pattern

查看:24
本文介绍了struts2 忽略特定模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

我的 web.xml 文件将类似于:

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>

现在,如果我像这样访问: http://localhost:8080/appName/ 它会完美地完成我的注册操作.但是当我尝试像 http://localhost:8080/appName/checking (对于网络服务)访问时,它甚至查看 struts.xml 并收到如下错误消息:

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 状态 404 - 没有为命名空间/和操作名称检查映射操作...即使在 web.xml 中定义了这个之后..

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

有什么办法排除struts2中的模式,这样当我点击http://localhost:8080/appName/checking,一定不能看struts action,它必须调用我在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.

谢谢..

推荐答案

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

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

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

阅读此处并查找 excludePattern 了解更多信息.

read here and find excludePattern for more information.

这篇关于struts2 忽略特定模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆