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. Content Provider Test过程中遇到的坑

    Content Provider(内容提供器) 一.什么是Content Provider? 直接贴官方文档简介图,笔者太懒了,而且 坑 不在这

  2. PHP 正则表达式匹配函数 preg_match 与 preg_match_all

    preg_match() preg_match() 函数用于进行正则表达式匹配,成功返回 1 ,否则返回 0 . 语法: 1 int preg_match( string pattern, strin ...

  3. hive导出查询文件到本地文件的2种办法

    通过HQL语句 可以将hive 中表的数据生成到指定的目录. 有时候 我们可以利用hive来生成统计的中间文件(比源文件小的多的) 方法有如下2种: 1.INSERT OVERWRITE LOCAL ...

  4. UML图学习之二 类图

    类图(ClassDiagrams)是根据系统中的类以及各类之间的关系描述系统的静态视图.类图不仅显示系统内信息的结构,还描述系统内这些信息的行为.类图的一个重要目的是为其他图(如顺序图.交互图)定义一 ...

  5. mybatis_helloword(1)

    摘录自:http://blog.csdn.net/y172158950/article/details/16979391 新的项目中用到mybatis,虽然不用自己写ORM的代码,但是借这个机会,学习 ...

  6. shell实例练习+详解

    想着将Shell与Python和Java等脚本比较比较,当一有这个念头我就放弃了.这太侮辱Shell了.(哭笑脸!) 作为一个程序员,Linux那是最基本要求.而shell脚本有时候也会显示它在Lin ...

  7. SVN使用基础

    1.安装svn centos:yum install subversion -y ubuntu:apt-get install subversion -y 2.创建库目录 mkdir /opt/.sv ...

  8. scrapy_cookie禁用_延迟下载_自定义爬虫setting

    如何设置禁止cookie? 在setting中 添加字段: COOKIE_ENABLED = False                            # False关闭cookie,True ...

  9. python_如何快速下载安装第三方库?

    如何快速下载安装第三方库? --通过 淘宝源  https://mirrors.aliyun.com/pypi/simple/ 本国网络进行快速安装 如何执行安装命令? pip install Dja ...

  10. Windows核心编程&线程

    1. 线程上下文:线程内核对象保存线程上一次执行时的CPU寄存器状态 2. 线程上下文切换 3. windows操作系统为抢占式多线程操作系统,系统可以在任何时刻停止一个线程而另行调度另外一个线程.我 ...