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

查看:104
本文介绍了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 (用于Web服务)时,它甚至在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动作,它必须调用在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天全站免登陆