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. ECharts插件的使用

    ECharts插件:官网下载echarts.js开发者可以选择源码.下载地址:http://echarts.baidu.com/download.html 下载之后,echarts.js放在js文件夹 ...

  2. 引导图滤波(Guided Image Filtering)原理以及OpenCV实现

    引导图是一种自适应权重滤波器,能够在平滑图像的同时起到保持边界的作用,具体公式推导请查阅原文献<Guided Image Filtering>.这里只说一下自适应权重原理.C++实现灰度图 ...

  3. jquery 循环获取checkBox的值,以及对复选框选中,取消,操作按钮

    法一:jquery 循环获取选中checkBox框的值 function checkeds() { $("input:checkbox").each(function(index) ...

  4. Spring 数据库连接(Connection)绑定线程(Thread)的实现

    最近在看spring事务的时候在想一个问题:spring中的很多bean都是单例的,是非状态的,而数据库连接是一种有状态的对象,所以spring一定在创建出connection之后在threadloc ...

  5. 如何去掉ul标签的多余空白或多余大距离?

    在css中写入 ul{ margin:; padding:; list-style: none; } 让其内边距和外边距为0,列表样式为空

  6. python_如何定义装饰器类?

    案例: 实现一个能将函数调用信息记录到日志的装饰器 需求: 把每次函数的调用时间,执行时间,调用次数写入日志 可以对被装饰函数分组,调用信息记录到不同日志 动态修改参数,比如日志格式 动态打开关闭日志 ...

  7. 实现iota函数

    void Reverse(char *s) { char temp; char *p = s; char *q = s; while (*p != '\0') { p ++; } q --; whil ...

  8. JavaScript事件高级绑定

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

  9. 基于Elasticsearch搜索平台设计

    背景 随着公司业务的高速发展以及数据爆炸式的增长,当前公司各产线都有关于搜索方面的需求,但是以前的搜索服务系统由于架构与业务上的设计,不能很好的满足各个业务线的期望,主要体现下面三个问题: 不能支持对 ...

  10. nodejs模块引用

    模块的引用是后端语言非常重要的一部分,那么在nodejs中,如何做到这一点呢. 在引用其他模块时,常用的就是两种方法:exports,module.exports. 接下来,我们写一个demo来分辨其 ...