Struts2中如何添加Servlet

以前Java开发都是Servlet的天下,如今是各种框架横行,遇到一个需要将以前的Servlet加入到现有的Struts2的环境中。

Google之后发现Stack Overflow真是个好东西,解决如下,只是简单配置下。

I assume you want to know how to use a servlet in conjunction with Struts2 when you have mapped everything to the Struts2 filter.

You can use the following in your struts.xml:

<constant name="struts.action.excludePattern" value="/YourServlet"/>
You can exclude multiple patterns by separating them with a comma, such as: <constant name="struts.action.excludePattern" value="/YourServlet,/YourOtherServlet"/>
参考

Filter mapping for everthing to Struts2 besides one servlet?

Filters not working in Struts2

Preventing Struts from Handling a Request

If there is a request that Struts is handling as an action, and you wish to make Struts ignore it, you can do so by specifying a comma separated list of regular expressions like:

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

These regular expression will be evaluated against the request's URI (HttpServletRequest.getRequestURI()), and if any of them matches, then Struts will not handle the request.

To evaluate each pattern Pattern class from JDK will be used, you can find more about what kind of pattern you can use in the Pattern class JavaDoc.

除了上面在Struts2 里面自带的方法

1. 在web.xml中配置需要请求的Servlet

<servlet-mapping>

<servlet-name>Authcode</servlet-name>

<url-pattern>/authcode.servlet</url-pattern>

</servlet-mapping>

2. 在过滤器中Request的请求进行Servlet判断并进行处理

参考

Struts2 中添加 Servlet的更多相关文章

  1. Struts2中使用Servlet API步骤

    Struts2中使用Servlet API步骤 Action类中声明request等对象 Map<String, Object> request; 获得ActionContext实例 Ac ...

  2. struts2中访问servlet API

    Struts2中的Action没有与任何Servlet API耦合,,但对于WEB应用的控制器而言,不访问Servlet API几乎是不可能的,例如需要跟踪HTTP Session状态等.Struts ...

  3. IDEA中添加servlet的jar

    问题解决:办法1:使用Project Structure 方法二:使用Maven 在pom.xml文件中添加如下

  4. Struts2中获取servlet API的几种方式

    struts2是一个全新的MVC框架,如今被广大的企业和开发者所使用,它的功能非常强大.这给我们在使用servlet 纯java代码写项目的时候带来了福音.但是一般来说,我们的项目不到一定规模并不需要 ...

  5. maven中添加servlet、jsp依赖

    或者在eclipse中,右键项目名称->Maven->Add Dependency->输入servlet,会自动找到最新的版本(记得联网哦),如图:

  6. 在web.xml中添加servlet报错问题

    出现这种问题的原因是因为servlet-name标签中没有名称,如果错误出现在servlet上,也是一样,补充servlet-name名称即可.如下图

  7. struts2中Action訪问servlet的两种方式

    一.IoC方式                在struts2框架中,能够通过IoC方式将servlet对象注入到Action中.通常须要Action实现下面接口: a. ServletRequest ...

  8. Struts2(八)访问Servlet API

    一.Struts2中的Servlet API 1.1.struts2的Action实现了MVC中C层的作用 针对请求用户显示不同的信息 登录后段保存用户信息 ----session 保存当前在线人数等 ...

  9. web项目中添加定时任务

    1.在web.xml中添加servlet <servlet> <servlet-name>StatisticInitServlet</servlet-name> & ...

随机推荐

  1. dedecms下的tplcache模板缓存文件过多怎么清理?

    时间:2016-04-18 09:32来源:www.ucbug.cc作者:网络 相信很多站长,或者seoer人员在备份用dedecms程序开发的网站时,发现下载到tplcache这个文件夹内容时候花了 ...

  2. WdatePicker设置时间区间时,对开始时间和结束时间限制

    <input id="startDate" name="startDate"  type="text" readonly=" ...

  3. 邓_ Php·笔记本[照片]

    -------------------------------------------------------------------------------------------- [PHP] - ...

  4. Java Enum解析【转】

    Enum用法: 1:常量 在JDK1.5 之前,我们定义常量都是: public static fianl.... .现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举提供了比常量更多 ...

  5. java中的按位与运算

    package scanner; public class SingleAnd { public static void main(String[] args) { int[] first = {10 ...

  6. VM安装Ubuntu问题合集(无法联网、中文界面设置、中文输入法etc)

    经常使用VM安装Ubuntu,安装系统的步骤跟着系统提示一步步下来就行,但总是遇到一些问题,这里记录一下常遇到的问题,以及自己解决的办法: 1.无法联网: 状况:Ubuntu不能联网,联网地方一直在闪 ...

  7. 深入理解final关键字以及一些建议

    引子:一说到final关键字,相信大家都会立刻想起一些基本的作用,那么我们先稍微用寥寥数行来回顾一下. 一.final关键字的含义 final是Java中的一个保留关键字,它可以标记在成员变量.方法. ...

  8. hashCode方法和equals方法比较

    为什么用HashCode比较比用equals方法比较要快呢?我们要想比较hashCode与equals的性能,得先了解HashCode是什么. HashCode HashCode是jdk根据对象的地址 ...

  9. JavaScript事件高级绑定

    js 进行事件绑定,其中一种不常见的写法是: <div id="father" style="width: 300px; height: 200px; backgr ...

  10. tomcat安装自制作ssl证书

    1.执行命令 C:\servers\apache-tomcat-8.0.27>keytool -genkey -alias tomcat -keyalg RSA -keypass pass123 ...