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> & ...
随机推荐
- Java | 原来 try 还可以这样用啊?!
本文首发于 http://youngzy.com/ 习惯了这样的try: try { } catch (Exception e) { } 看到了这样的try,觉得有点神奇: try(...) { } ...
- vue中使用Ueditor编辑器
一. 下载包: 从Ueditor的官网下载1.4.3.3jsp版本的Ueditor编辑器,官网地址为: http://ueditor.baidu.com/website/ 下载解压后会得到如果下文 ...
- ajax_表单提交+tp5ajax
======================================================= 判断squery导入的是否正确? $(function(){ alert('1'); } ...
- Python 3 利用 Dlib 19.7 和 sklearn机器学习模型 实现人脸微笑检测
0.引言 利用机器学习的方法训练微笑检测模型,给一张人脸照片,判断是否微笑: 使用的数据集中69张没笑脸,65张有笑脸,训练结果识别精度在95%附近: 效果: 图1 示例效果 工程利用pytho ...
- zabbix入门知识
zabbix入门知识 zabbix中文手册 https://www.zabbix.com/documentation/3.4/manual/ 1.zabbix介绍 Zabbix 是一个企业级的分布式开 ...
- Asp.net mvc 中Action 方法的执行(二)
[toc] 前面介绍了 Action 执行过程中的几个基本的组件,这里介绍 Action 方法的参数绑定. 数据来源 为 Action 方法提供参数绑定的原始数据来源于当前的 Http 请求,可能包含 ...
- myeclipse 奔溃解决办法
myeclipse 突然奔溃 解决办法 JVM terminated.Exit code=1 意思是说java 虚拟机挂了,而不是myeclipse挂了. 进入myeclipse 目录 查看myecl ...
- python_利用高阶函数实现剪枝函数
案例: 某些时候,我们想要为多个函数,添加某种功能,比如计时统计,记录日志,缓存运算结果等等 需求: 在每个函数中不需要添加完全相同的代码 如何解决? 把相同的代码抽调出来,定义成装饰器 求斐波那契数 ...
- BSA Network Shell系列-nsh命令
nsh nsh命令软链接到zsh,直接运行nsh可进入Network Shell,所有的Network Shell命令都需要运行nsh进入Network Shell执行 1 使用cd命令访问远程主机和 ...
- junit--eclipse插件
现在比较火的IDE是JIDE,但是我一直在使用eclipse.对eclipse比较熟悉了,也有了感情了.这里就以eclipse为例,来整理下eclipse中junit插件的使用. 添加junit包到自 ...