Struts2 中添加 Servlet
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
- 其实Struts2 的文档中有记载Static Content
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的更多相关文章
- Struts2中使用Servlet API步骤
Struts2中使用Servlet API步骤 Action类中声明request等对象 Map<String, Object> request; 获得ActionContext实例 Ac ...
- struts2中访问servlet API
Struts2中的Action没有与任何Servlet API耦合,,但对于WEB应用的控制器而言,不访问Servlet API几乎是不可能的,例如需要跟踪HTTP Session状态等.Struts ...
- IDEA中添加servlet的jar
问题解决:办法1:使用Project Structure 方法二:使用Maven 在pom.xml文件中添加如下
- Struts2中获取servlet API的几种方式
struts2是一个全新的MVC框架,如今被广大的企业和开发者所使用,它的功能非常强大.这给我们在使用servlet 纯java代码写项目的时候带来了福音.但是一般来说,我们的项目不到一定规模并不需要 ...
- maven中添加servlet、jsp依赖
或者在eclipse中,右键项目名称->Maven->Add Dependency->输入servlet,会自动找到最新的版本(记得联网哦),如图:
- 在web.xml中添加servlet报错问题
出现这种问题的原因是因为servlet-name标签中没有名称,如果错误出现在servlet上,也是一样,补充servlet-name名称即可.如下图
- struts2中Action訪问servlet的两种方式
一.IoC方式 在struts2框架中,能够通过IoC方式将servlet对象注入到Action中.通常须要Action实现下面接口: a. ServletRequest ...
- Struts2(八)访问Servlet API
一.Struts2中的Servlet API 1.1.struts2的Action实现了MVC中C层的作用 针对请求用户显示不同的信息 登录后段保存用户信息 ----session 保存当前在线人数等 ...
- web项目中添加定时任务
1.在web.xml中添加servlet <servlet> <servlet-name>StatisticInitServlet</servlet-name> & ...
随机推荐
- Navicat连接阿里云Mysql遇到的的坑
连上去那一刻,心态真是起飞了
- SpringBoot Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
SpringBoot Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFact ...
- Web前端性能优化——如何提高页面加载速度
前言: 在同样的网络环境下,两个同样能满足你的需求的网站,一个"Duang"的一下就加载出来了,一个纠结了半天才出来,你会选择哪个?研究表明:用户最满意的打开网页时间是2-5秒, ...
- PHP操作MySQL对表增加一列(一个字段)
2014-03-19 16:59 1471人阅读 评论(0) 收藏 举报 分类: MySQL(12) 对于已经建立好的数据库,在一个已经有字段的表内新加字段可用以下方法: mysql_query(&q ...
- 全新的软件项目,好的开始决定了成功一半!(需求&计划)
刚看完“无问西东”,电影里说人总归还是要留下些足迹(文字)的,那么赶紧跑图书馆来留下些文字. 最近去瑞士启动了一个新的项目,那么早上做项目,晚上总结留下了一张张思维导图来记录当时的感受, 手稿如下,字 ...
- mmap 测试的一些坑
最近遇到一个mmap的问题,然后为了测试该问题,写了如下测试代码: #include <sys/mman.h> #include <sys/stat.h> #include & ...
- MySQL 水平拆分(读书笔记整理)
转:http://blog.csdn.net/mchdba/article/details/46278687 1,水平拆分的介绍 一般来说,简单的水平切分主要是将某个访问极其平凡的表再按照某个字段的某 ...
- Linux exec与文件描述符
看到好几篇文章讲述exec都是一知半解,所以我尽量说的清楚明白一些.本文首先讲述Linux文件描述符,然后是exec,最后举例说明exec I/O重定向及其用法. 概念:exec命令用于调用并执行指令 ...
- 请求服务(RequestService)
一个module中的web组件,负责将Service的结果按照适当的规范输出给前端.格式:http://server/moduleID/param0/param1/paramN/p.TYPE格式上包含 ...
- Log4net使用详细说明
1.概述 log4net是.Net下一个非常优秀的开源日志记录组件.log4net记录日志的功能非常强大.它可以将日志分不同的等级,以不同的格式,输出到不同的媒介.本文主要是介绍如何在Visual S ...