【JavaEE企业应用实战学习记录】authorityFilter
package sanglp.servlet; import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException; /**
* Created by Administrator on 2016/10/5.
*/
@WebFilter(filterName = "authority",urlPatterns = {"/*"},initParams = {
@WebInitParam(name = "encoding",value = "UTF-8"),
@WebInitParam(name = "loginPage",value = "/chap2/login.jsp"),
@WebInitParam(name = "proLogin", value="/chap2/proLogin.jsp")
})
public class AuthorityFilter implements Filter {
//用于访问Filter的配置信息
private FilterConfig config; @Override
public void init(FilterConfig filterConfig) throws ServletException {
this.config=filterConfig;
} @Override
public void destroy() {
this.config=null;
} @Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//获取该Filter的配置参数
String encoding=config.getInitParameter("encoding");
String loginPage=config.getInitParameter("loginPage");
String proLogin=config.getInitParameter("proLogin");
//设置request编码用的字符集
servletRequest.setCharacterEncoding(encoding);
HttpServletRequest hreq=(HttpServletRequest) servletRequest;
HttpSession session=hreq.getSession(true);
//获取客户请求的页面
String requestPath=hreq.getServletPath();
//如果session范围的user为null即表明没有邓丽。且用户请求的既不是登录页面,也不是处理登录的页面
if(session.getAttribute("user")==null&&!requestPath.endsWith(loginPage)&&!requestPath.endsWith(proLogin)){
servletRequest.setAttribute("tip","您还没有登录");
servletRequest.getRequestDispatcher(loginPage).forward(servletRequest,servletResponse); }else{
//履行请求
filterChain.doFilter(servletRequest,servletResponse);
}
}
}
【JavaEE企业应用实战学习记录】authorityFilter的更多相关文章
- 【JavaEE企业应用实战学习记录】optiontransferselect实现两个列表选择框
<%@ page contentType="text/html; charset=GBK" language="java"%> <%@tagl ...
- 【JavaEE企业应用实战学习记录】logFilter
package sanglp.servlet; import javax.servlet.*; import javax.servlet.annotation.WebFilter; import ja ...
- 【JavaEE企业应用实战学习记录】struts2实现登录并获取各个范围的数据
package sanglp; import com.opensymphony.xwork2.*; /** * Created by Administrator on 2016/10/6. */ pu ...
- 【JavaEE企业应用实战学习记录】struts配置文件详细解析
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-/ ...
- 【JavaEE企业应用实战学习记录】struts2登录
<%-- login.jsp Created by IntelliJ IDEA. User: Administrator Date: 2016/10/6 Time: 16:26 To chang ...
- 【JavaEE企业应用实战学习记录】struts国际化
<%-- Created by IntelliJ IDEA. User: Administrator Date: 2016/10/6 Time: 16:26 To change this tem ...
- 【JavaEE企业应用实战学习记录】servlet3.0上传文件
<%-- Created by IntelliJ IDEA. User: Administrator Date: 2016/10/6 Time: 14:20 To change this tem ...
- 【JavaEE企业应用实战学习记录】sessionListener
package sanglp.servlet; import javax.servlet.ServletContext; import javax.servlet.annotation.WebList ...
- 【JavaEE企业应用实战学习记录】requestListener
package sanglp.servlet; import javax.servlet.*; import javax.servlet.annotation.WebListener; import ...
随机推荐
- jQuery 3.0 的变化
时隔 3 个月,jQuery 团队终于发布了 3.0 Alpha 版本.有两个版本 jQuery compat 3.0 和 jQuery 3.0. jQuery compat 3.0 对应之前的 1. ...
- Tomcat免安装配置
大家都知道tomcat吧!因为Tomcat 技术先进.性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器,也是运行Servlet和JS ...
- 汽车4S店经验指标完成情况报表制作分享
集团公司一般为了加强下属的经营管理,以及项经营指标完情况,需要制定一些报表.我们平时也经常遇到这种情况,而这些报表要包括什么内容呢?该怎么制作呢?用什么制作呢?今天小编就以4s店为例,分享给大家一个报 ...
- 理解 QEMU/KVM 和 Ceph(2):QEMU 的 RBD 块驱动(block driver)
本系列文章会总结 QEMU/KVM 和 Ceph 之间的整合: (1)QEMU-KVM 和 Ceph RBD 的 缓存机制总结 (2)QEMU 的 RBD 块驱动(block driver) (3)存 ...
- 新手ui设计师必备——切图规范
图文并茂,浅显易懂. 使用markman标注. 资源链接: 图片来自http://www.ui.cn/detail/56347.html 本文作者starof,因知识本身在变化,作者也在不断学习成长, ...
- SVN报Previous operation has not finished; run 'cleanup' if it was interrupted错误的解决方法
做着项目突然SVN报Previous operation has not finished; run 'cleanup' if it was interrupted,进度又要继续,烦.百度一下发现很多 ...
- POJ3463Sightseeing[次短路计数]
Sightseeing Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8707 Accepted: 3056 Descr ...
- CSS中的常用属性
一 CSS文字属性:color : #999999; /*文字颜色*/font-family : 宋体,sans-serif; /*文字字体*/font-size : 9pt; /*文字大小*/fon ...
- poj1416 Shredding Company
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5379 Accepted: 3023 ...
- 基于jquery的tips悬浮消息提示插件tipso
<a href="javascript:;" class="disabled" data-tipso="Tips" id=" ...