j2ee中如何拦截jsp页面?
加filter:
- public class RightFilter implements Filter {
- public void init(FilterConfig filterConfig) throws ServletException {
- }
- public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
- FilterChain filterChain) throws IOException, ServletException {
- HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
- HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
- User user = (User) httpServletRequest.getSession(true).getAttribute("user");
- if (!isExcludePages(httpServletRequest.getRequestURI())) {
- if (user == null) {
- httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/login.jsp");
- return;
- }
- }
- filterChain.doFilter(servletRequest, servletResponse);
- }
- private boolean isExcludePages(String url) {
- return url.indexOf("login.dhtml") != -1
- || url.indexOf("logout.dhtml") != -1
- || url.indexOf("login.jsp") != -1
- || url.endsWith(".css")
- || url.endsWith(".js")
- || url.endsWith(".gif")
- || url.endsWith(".jpg")
- || url.endsWith(".png");
- }
- public void destroy() {
- }
- }
需要在web.xml里面配置一下:
- <filter>
- <filter-name>rightFilter</filter-name>
- <filter-class>com.xxx.filter.RightFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>rightFilter</filter-name>
- <url-pattern>*.dhtml</url-pattern>
- </filter-mapping>
j2ee中如何拦截jsp页面?的更多相关文章
- springmvc登录拦截jsp页面
web.xml配置 <filter> <filter-name>LoginFilter</filter-name> //编写拦截的类的全类名 <filter- ...
- js 和 css 中 不能使用 jsp 页面中一些 标签 和 java 代码等,应注意
js 和 css 中 不能使用 jsp 页面中一些 标签 和 java 代码等,应注意 如 ${ } <%%> 等
- 过滤器Filter(拦截jsp页面的跳转)案例:
创建一个 Filter , class类: 其继承于 接口 Filte(接口导包:import javax.servlet.Filter;) 在 web.xml 文件中配置并映射该 Filter. 其 ...
- myeclipse学习总结一(在MyEclipse中设置生成jsp页面时默认编码为utf-8编码)
1.每次我们在MyEclispe中创建Jsp页面,生成的Jsp页面的默认编码是"ISO-8859-1".在这种情况下,当我们在页面中编写的内容存在中文的时候,就无法进行保存.如下图 ...
- 在action中将字符串、对象、list集合保存到值栈中,在jsp页面中获取的方法
转自:csdn 封装对象User,属性有id,username,email等1.1:在action中将字符串保存到值栈中 1.1.1 获取值栈对象 ValueStack stack ...
- jsp中Java代码中怎么获取jsp页面元素
举例,页面元素<td><input value="${sl }" type="text" id="sl" name=& ...
- 从后台servlet中,获取jsp页面输入的值,来删除用户一行信息
后台servlet设置 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws S ...
- 将项目导入eclipse中出现的jsp页面报错
图片摘自百度经验,实在是每次都会忘了步骤,每次都得重新百度,所以索性自己总结到博客中,下次如果还记不住就直接从博客中看.原谅我实在学渣,呜呜~~~~(>_<)~~~~
- 将项目导入eclipse中出现的jsp页面报错解决
随机推荐
- iOS开发——新特性OC篇&Swift 2.0新特性
Swift 2.0新特性 转眼间,Swift已经一岁多了,这门新鲜.语法时尚.类型安全.执行速度更快的语言已经渐渐的深入广大开发者的心.我同样也是非常喜爱这门新的编程语言. 今年6月,一年一度 ...
- JavaScript中Get和Set访问器的实现
我们常用的实现方法可能是这样的: function Field(val){ var value = val; this.getValue =function(){ return value; }; t ...
- interactive_timeout和wait_timeout(
mysql> show variables like "%timeout%"; +-----------------------------+----------+ | Va ...
- Dubbo架构设计详解--转载
原文地址:http://shiyanjun.cn/archives/325.html Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解 ...
- Reviewing the Blog Module
Reviewing the Blog Module Throughout the tutorial, we have created a fully functional CRUD module us ...
- chrome,firefox
chrome开发者工具 firefox插件httpfox
- 转:解决OM的Price List输入找不到对应库存的ITEMS的问题
一,保证Item Validation Organization参数的值一致 Item Validation Organization参数的值是填库存组织,通过这个值,可以分隔OM所能使用的库存Ite ...
- Linux Shell产生16进制随机数
n为字符长度 openssl rand -hex n
- 滚动新闻插件vticker
vTicker 是一款非常小巧的 jQuery 垂直滚动插件,压缩后只有 2KB.vTicker 支持自定义滚动时间.间隔时间.显示个数.滚动方向(向上/向下).容器高度等等,但它对 HTML 结构有 ...
- PHP自动化测试
参考网址: 1. 基于Jenkins 实现php项目的自动化测试.自动打包和自动部署 2. PHP Jenkins,参考:http://jenkins-php.org/ 3.安装PHP_CodeSn ...