加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页面?的更多相关文章

  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. Mysql数据库备份和按条件导出表数据

    Mysql数据库备份和按条件导出表数据   一.备份数据库 # mysqldump -u root -p  dbcurr>/home/20090219.sql   mysqldum为备份命令,- ...

  2. Beyond MySQL --Branching the popular database--转载

    原文:http://www.ibm.com/developerworks/library/os-beyondmysql/ Introduction MySQL is one of the most p ...

  3. JQuery+EasyUI弹窗代码

    来源:http://www.cnblogs.com/taven/p/3330125.html <head>需要引用的文件: <link href="../JS/EasyUi ...

  4. 【原】Spring与MongoDB集成:仓库

    上一篇文章用介绍了如何配置spring-data-mongo连接到MongoDB上,如何创建MongoTemplate.MongoTemplate就相当于一个通用的仓库,可以持久化业务对象. 在spr ...

  5. 【转】Android自动化测试之MonkeyRunner录制和回放脚本(四)

    测试脚本录制: 方案一: 我们先看看以下monkeyrecoder.py脚本: #Usage: monkeyrunner recorder.py #recorder.py  http://mirror ...

  6. 类结构体 与 byte[] 转换类

    public static class StructConvert { public static object BytesToStruct(byte[] bytes, Type strcutType ...

  7. dede-搜索

    <form name="formsearch" action="{dede:global.cfg_cmsurl/}/plus/search.php"> ...

  8. 揭开CSS3媒体查询迷雾(min-width和max-width)

    本文参考MichelleKlann的Media Queries Demystified: Min-Width and Max-Width 媒体查询(media queries)是响应式设计(Respo ...

  9. ORCAL

    select name from v$database;--查询当前数据库名: select instance_name from v$instance;--查询当前数据库实例名 select def ...

  10. spark下测试akka的分布式通讯功能

    采用的spark版本为1.1.0 scala版本为2.10.4 编写scala类文件myactors.scala: package bluejoe import akka.actor._ import ...