加filter:

  1. public class RightFilter implements Filter {
  2. public void init(FilterConfig filterConfig) throws ServletException {
  3. }
  4.  
  5. public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
  6. FilterChain filterChain) throws IOException, ServletException {
  7. HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
  8. HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
  9. User user = (User) httpServletRequest.getSession(true).getAttribute("user");
  10. if (!isExcludePages(httpServletRequest.getRequestURI())) {
  11. if (user == null) {
  12. httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/login.jsp");
  13. return;
  14. }
  15. }
  16. filterChain.doFilter(servletRequest, servletResponse);
  17. }
  18.  
  19. private boolean isExcludePages(String url) {
  20. return url.indexOf("login.dhtml") != -1
  21. || url.indexOf("logout.dhtml") != -1
  22. || url.indexOf("login.jsp") != -1
  23. || url.endsWith(".css")
  24. || url.endsWith(".js")
  25. || url.endsWith(".gif")
  26. || url.endsWith(".jpg")
  27. || url.endsWith(".png");
  28. }
  29.  
  30. public void destroy() {
  31. }
  32. }

需要在web.xml里面配置一下:

  1. <filter>
  2. <filter-name>rightFilter</filter-name>
  3. <filter-class>com.xxx.filter.RightFilter</filter-class>
  4. </filter>
  5.  
  6. <filter-mapping>
  7. <filter-name>rightFilter</filter-name>
  8. <url-pattern>*.dhtml</url-pattern>
  9. </filter-mapping>

j2ee中如何拦截jsp页面?的更多相关文章

  1. springmvc登录拦截jsp页面

    web.xml配置 <filter> <filter-name>LoginFilter</filter-name> //编写拦截的类的全类名 <filter- ...

  2. js 和 css 中 不能使用 jsp 页面中一些 标签 和 java 代码等,应注意

    js  和 css 中 不能使用 jsp  页面中一些 标签 和 java 代码等,应注意 如 ${ }  <%%>  等

  3. 过滤器Filter(拦截jsp页面的跳转)案例:

    创建一个 Filter , class类: 其继承于 接口 Filte(接口导包:import javax.servlet.Filter;) 在 web.xml 文件中配置并映射该 Filter. 其 ...

  4. myeclipse学习总结一(在MyEclipse中设置生成jsp页面时默认编码为utf-8编码)

    1.每次我们在MyEclispe中创建Jsp页面,生成的Jsp页面的默认编码是"ISO-8859-1".在这种情况下,当我们在页面中编写的内容存在中文的时候,就无法进行保存.如下图 ...

  5. 在action中将字符串、对象、list集合保存到值栈中,在jsp页面中获取的方法

    转自:csdn 封装对象User,属性有id,username,email等1.1:在action中将字符串保存到值栈中   1.1.1 获取值栈对象         ValueStack stack ...

  6. jsp中Java代码中怎么获取jsp页面元素

    举例,页面元素<td><input   value="${sl }" type="text" id="sl" name=& ...

  7. 从后台servlet中,获取jsp页面输入的值,来删除用户一行信息

    后台servlet设置 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws S ...

  8. 将项目导入eclipse中出现的jsp页面报错

    图片摘自百度经验,实在是每次都会忘了步骤,每次都得重新百度,所以索性自己总结到博客中,下次如果还记不住就直接从博客中看.原谅我实在学渣,呜呜~~~~(>_<)~~~~

  9. 将项目导入eclipse中出现的jsp页面报错解决

随机推荐

  1. iOS开发——新特性OC篇&Swift 2.0新特性

    Swift 2.0新特性     转眼间,Swift已经一岁多了,这门新鲜.语法时尚.类型安全.执行速度更快的语言已经渐渐的深入广大开发者的心.我同样也是非常喜爱这门新的编程语言. 今年6月,一年一度 ...

  2. JavaScript中Get和Set访问器的实现

    我们常用的实现方法可能是这样的: function Field(val){ var value = val; this.getValue =function(){ return value; }; t ...

  3. interactive_timeout和wait_timeout(

    mysql> show variables like "%timeout%"; +-----------------------------+----------+ | Va ...

  4. Dubbo架构设计详解--转载

    原文地址:http://shiyanjun.cn/archives/325.html Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解 ...

  5. Reviewing the Blog Module

    Reviewing the Blog Module Throughout the tutorial, we have created a fully functional CRUD module us ...

  6. chrome,firefox

    chrome开发者工具 firefox插件httpfox

  7. 转:解决OM的Price List输入找不到对应库存的ITEMS的问题

    一,保证Item Validation Organization参数的值一致 Item Validation Organization参数的值是填库存组织,通过这个值,可以分隔OM所能使用的库存Ite ...

  8. Linux Shell产生16进制随机数

    n为字符长度 openssl rand -hex n

  9. 滚动新闻插件vticker

    vTicker 是一款非常小巧的 jQuery 垂直滚动插件,压缩后只有 2KB.vTicker 支持自定义滚动时间.间隔时间.显示个数.滚动方向(向上/向下).容器高度等等,但它对 HTML 结构有 ...

  10. PHP自动化测试

    参考网址: 1. 基于Jenkins 实现php项目的自动化测试.自动打包和自动部署 2.  PHP Jenkins,参考:http://jenkins-php.org/ 3.安装PHP_CodeSn ...