如何配置 URL 模式以使 servlet 和 Struts2 同时工作? [英] How to configure URL patterns to have servlet and Struts2 to work simultaneously?

查看:21
本文介绍了如何配置 URL 模式以使 servlet 和 Struts2 同时工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的过滤对我不起作用以及如何设置它?

Why my filtering does not work for me and how to setup it to work?

有我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
    <display-name>GameServlet</display-name>
    <servlet-name>GameServlet</servlet-name>
    <servlet-class>ajaxdemo.action.GameServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>GameServlet</servlet-name>
    <url-pattern>/gameservlet</url-pattern>
</servlet-mapping>
<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>

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

在这个配置中 GameServlet 没有收到任何东西,并且网络服务器报告说没有 /gameservlet URL 的动作映射.

On this configuration GameServlet does not receive anything and web server reports that there are no action mapping for /gameservlet URL.

如果我评论过滤器映射,这个 servlet 通过这个 URL 可以正常工作.

If I comment filter-mapping this servlet works fine by this URL.

如何让Struts过滤器和servlet过滤器同时工作,重点是servlet应该只与/gameservlet URL一起工作,所有其他的都应该由Struts处理.我无法理解如何为我的案例创建 URL 模式.

How to get working Struts filters and servlet filter simultaneously, the point is servlet should work only with /gameservlet URL, all others should be processed by Struts. I cannot understand how to create URL patterns for my case.

推荐答案

您应该将 excludePattern 常量添加到 struts.xml 以从 Struts 处理中排除 servlet 映射 URL.

You should add excludePattern constant to struts.xml to exclude servlet mapping URL from Struts processing.

<struts>
    <constant name="struts.action.excludePattern" value="/gameservlet/?.*"/>
    ...
</struts> 

这篇关于如何配置 URL 模式以使 servlet 和 Struts2 同时工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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