过滤器的正确打开方式

原创 2015年07月07日 23:38:24



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>ROOT</display-name>
<!-- 权限拦截器 -->
<filter>
<filter-name>LimitsFilter</filter-name>
<filter-class>com.lg.filter.LimitsFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<!-- 初始化指定需要进行特殊权限拦截的页面 -->
<init-param>
<param-name>ZXLOVE</param-name>
<param-value>/jsp/list/zxnet/zxlove/zxlove.htm</param-value>
</init-param>
<init-param>
<param-name>ZXSB</param-name>
<param-value>/jsp/list/zxnet/zxsb/1.html</param-value>
</init-param>
<init-param>
<param-name>CZ</param-name>
<param-value>/jsp/list/zxnet/cz/1.html</param-value>
</init-param>
<init-param>
<param-name>QLS</param-name>
<param-value>/jsp/list/photos/qls/index.html</param-value>
</init-param>
<init-param>
<param-name>XDH</param-name>
<param-value>/jsp/list/photos/xdh/index.html</param-value>
</init-param>
<init-param>
<param-name>MA</param-name>
<param-value>/jsp/others/backmanage/index.jsp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>LimitsFilter</filter-name>
<url-pattern>/jsp/others/about/*</url-pattern>
<url-pattern>/jsp/others/backmanage/*</url-pattern>
<url-pattern>/jsp/others/blog/*</url-pattern>
<url-pattern>/jsp/others/share/main.jsp</url-pattern>
<url-pattern>/jsp/others/webnote/*</url-pattern>
<url-pattern>/jsp/others/ChatingRoom/index.jsp</url-pattern>
<url-pattern>/jsp/list/zxnet/*</url-pattern>
<url-pattern>/jsp/list/photos/*</url-pattern>
</filter-mapping>
<!-- 聊天室字符集过滤器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>com.lg.chat.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<!-- 监听器注册 -->
<listener>
<listener-class>
com.lg.chat.servlet.UserListener
</listener-class>
</listener>
 
 
 
<!-- 设置站内session默认生命周期:10min -->
<session-config>
<session-timeout>10</session-timeout>
</session-config>
 
<!-- 站内Error指定页面跳转 -->
<error-page>
<error-code>400</error-code>
<location>/ehtml/400.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/ehtml/403.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/ehtml/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/ehtml/500.jsp</location>
</error-page>
<error-page>
<error-code>502</error-code>
<location>/ehtml/502.jsp</location>
</error-page>
<error-page>
<error-code>503</error-code>
<location>/ehtml/503.jsp</location>
</error-page>
<error-page>
<error-code>504</error-code>
<location>/ehtml/504.jsp</location>
</error-page>
<error-page>
<error-code>505</error-code>
<location>/ehtml/505.jsp</location>
</error-page>
<!-- <error-page>
<exception-type>java.lang.NullException</exception-type>
<location>/ehtml/nullerror.html</location>
</error-page>
<error-page>
<exception-type>java.lang.IllegalArgumentException</exception-type>
<location>/ehtml/nullerror.html</location>
</error-page> -->
 
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>



package com.lg.filter;
 
import com.lg.entity.User;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
 
public class LimitsFilter
implements Filter
{
private FilterConfig config;
 
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
String encoding = this.config.getInitParameter("encoding");
String ZXLOVE = this.config.getInitParameter("ZXLOVE");
String ZXSB = this.config.getInitParameter("ZXSB");
String CZ = this.config.getInitParameter("CZ");
String QLS = this.config.getInitParameter("QLS");
String XDH = this.config.getInitParameter("XDH");
String MA = this.config.getInitParameter("MA");
 
request.setCharacterEncoding(encoding);
HttpServletRequest requ = (HttpServletRequest)request;
HttpSession session = requ.getSession(true);
 
String requestPath = requ.getServletPath();
 
if (session.getAttribute("user") == null)
{
request.getRequestDispatcher("/ehtml/nologin.jsp").forward(request, response);
}
else if ((session.getAttribute("user") != null) && ((requestPath.endsWith(ZXLOVE)) || (requestPath.endsWith(ZXSB)) || (requestPath.endsWith(CZ)) || (requestPath.endsWith(QLS)) || (requestPath.endsWith(XDH)) || (requestPath.endsWith(MA)))) {
User user = (User)session.getAttribute("user");
if ("A".equals(user.getQx()))
chain.doFilter(request, response);
else
request.getRequestDispatcher("/ehtml/notenoughqx.jsp").forward(request, response);
}
else if ((session.getAttribute("user") != null) && (!requestPath.endsWith(ZXLOVE)) && (!requestPath.endsWith(ZXSB)) && (!requestPath.endsWith(CZ)) && (!requestPath.endsWith(QLS)) && (!requestPath.endsWith(XDH)) && (!requestPath.endsWith(MA))) {
chain.doFilter(request, response);
} else {
request.getRequestDispatcher("/ehtml/500.jsp").forward(request, response);
}
}
 
public void init(FilterConfig config)
throws ServletException
{
this.config = config;
}
 
public void destroy() {
this.config = null;
}
}

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>ROOT</display-name>
<!-- 权限拦截器 -->
<filter>
<filter-name>LimitsFilter</filter-name>
<filter-class>com.lg.filter.LimitsFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<!-- 初始化指定需要进行特殊权限拦截的页面 -->
<init-param>
<param-name>ZXLOVE</param-name>
<param-value>/jsp/list/zxnet/zxlove/zxlove.htm</param-value>
</init-param>
<init-param>
<param-name>ZXSB</param-name>
<param-value>/jsp/list/zxnet/zxsb/1.html</param-value>
</init-param>
<init-param>
<param-name>CZ</param-name>
<param-value>/jsp/list/zxnet/cz/1.html</param-value>
</init-param>
<init-param>
<param-name>QLS</param-name>
<param-value>/jsp/list/photos/qls/index.html</param-value>
</init-param>
<init-param>
<param-name>XDH</param-name>
<param-value>/jsp/list/photos/xdh/index.html</param-value>
</init-param>
<init-param>
<param-name>MA</param-name>
<param-value>/jsp/others/backmanage/index.jsp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>LimitsFilter</filter-name>
<url-pattern>/jsp/others/about/*</url-pattern>
<url-pattern>/jsp/others/backmanage/*</url-pattern>
<url-pattern>/jsp/others/blog/*</url-pattern>
<url-pattern>/jsp/others/share/main.jsp</url-pattern>
<url-pattern>/jsp/others/webnote/*</url-pattern>
<url-pattern>/jsp/others/ChatingRoom/index.jsp</url-pattern>
<url-pattern>/jsp/list/zxnet/*</url-pattern>
<url-pattern>/jsp/list/photos/*</url-pattern>
</filter-mapping>
<!-- 聊天室字符集过滤器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>com.lg.chat.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<!-- 监听器注册 -->
<listener>
<listener-class>
com.lg.chat.servlet.UserListener
</listener-class>
</listener>
 
 
 
<!-- 设置站内session默认生命周期:10min -->
<session-config>
<session-timeout>10</session-timeout>
</session-config>
 
<!-- 站内Error指定页面跳转 -->
<error-page>
<error-code>400</error-code>
<location>/ehtml/400.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/ehtml/403.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/ehtml/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/ehtml/500.jsp</location>
</error-page>
<error-page>
<error-code>502</error-code>
<location>/ehtml/502.jsp</location>
</error-page>
<error-page>
<error-code>503</error-code>
<location>/ehtml/503.jsp</location>
</error-page>
<error-page>
<error-code>504</error-code>
<location>/ehtml/504.jsp</location>
</error-page>
<error-page>
<error-code>505</error-code>
<location>/ehtml/505.jsp</location>
</error-page>
<!-- <error-page>
<exception-type>java.lang.NullException</exception-type>
<location>/ehtml/nullerror.html</location>
</error-page>
<error-page>
<exception-type>java.lang.IllegalArgumentException</exception-type>
<location>/ehtml/nullerror.html</location>
</error-page> -->
 
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>



package com.lg.filter;
 
import com.lg.entity.User;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
 
public class LimitsFilter
implements Filter
{
private FilterConfig config;
 
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
String encoding = this.config.getInitParameter("encoding");
String ZXLOVE = this.config.getInitParameter("ZXLOVE");
String ZXSB = this.config.getInitParameter("ZXSB");
String CZ = this.config.getInitParameter("CZ");
String QLS = this.config.getInitParameter("QLS");
String XDH = this.config.getInitParameter("XDH");
String MA = this.config.getInitParameter("MA");
 
request.setCharacterEncoding(encoding);
HttpServletRequest requ = (HttpServletRequest)request;
HttpSession session = requ.getSession(true);
 
String requestPath = requ.getServletPath();
 
if (session.getAttribute("user") == null)
{
request.getRequestDispatcher("/ehtml/nologin.jsp").forward(request, response);
}
else if ((session.getAttribute("user") != null) && ((requestPath.endsWith(ZXLOVE)) || (requestPath.endsWith(ZXSB)) || (requestPath.endsWith(CZ)) || (requestPath.endsWith(QLS)) || (requestPath.endsWith(XDH)) || (requestPath.endsWith(MA)))) {
User user = (User)session.getAttribute("user");
if ("A".equals(user.getQx()))
chain.doFilter(request, response);
else
request.getRequestDispatcher("/ehtml/notenoughqx.jsp").forward(request, response);
}
else if ((session.getAttribute("user") != null) && (!requestPath.endsWith(ZXLOVE)) && (!requestPath.endsWith(ZXSB)) && (!requestPath.endsWith(CZ)) && (!requestPath.endsWith(QLS)) && (!requestPath.endsWith(XDH)) && (!requestPath.endsWith(MA))) {
chain.doFilter(request, response);
} else {
request.getRequestDispatcher("/ehtml/500.jsp").forward(request, response);
}
}
 
public void init(FilterConfig config)
throws ServletException
{
this.config = config;
}
 
public void destroy() {
this.config = null;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

STM32F4 DMA双缓冲的正确打开方式

  • 2016年08月03日 15:33
  • 47KB
  • 下载

【工业智能】工业智能的正确打开方式-用技术的创新做服务的价值

来源:天泽智云 授权 产业智能官 转载。 6月28日下午,2017贵州装备工业博览会暨制造业与互联网融合工业云经验交流会在贵阳会展中心召开。本次会议由工业和信息化部指导,贵州省经济和信息化委...

第一次玩树莓派的正确打开方式以及配置

最近一时兴起就买了一块树莓派,想在它上边做做开发,型号是Pi 3 Model B,因为以前硬件玩的少,所以这次真可谓是吃尽了苦头,下面我先简单的介绍一下我当时所处的情景。          因为是临时...

Android Dialog与软键盘的正确打开方式

1.写在前面2017年的第一篇博客,首先祝大家新年快乐,在新的一年里健健康康、平平安安!本篇博客的主要内容是关于在Dialog中软键盘的显示与隐藏问题,需求是在Dialog中有一个密码输入框,弹出Di...

看【js倒计时正确打开方式】笔记

看到这一篇:https://github.com/gomeplusFED/blog/blob/master/2016-04/do-you-really-understand-how-to-write-...
  • natsuyu
  • natsuyu
  • 2016年06月02日 22:22
  • 216

Activity的正确打开方式

Activity的正确打开方式 2016-08-21 TRANSLATION 原文地址:Explain Activity Launch Mode With E...

Dubbo的正确打开方式之基本接口定义及异常处理

为什么要写这篇文章呢?因为公司在使用Dubbo时并没有对Dubbo的用法做深入的了解,而是属于拿来就用,随着自己的想法来使用。这样很不好,就像天龙八部的鸠摩智练习错误的六脉神剑一样,方式不对,就容易走...

【Eclipse的正确打开方式】从StarUML到GEF到AmaterasUML

因为要写论文,想找个优雅一点的姿势画类图,当时不知道怎么想的,在viso和StarUML里选了后者(是的,我就是有自虐倾向),后来在一抹黑的界面上捣鼓了半天才知道现在能用的只有破解版……StarUML...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:过滤器的正确打开方式
举报原因:
原因补充:

(最多只允许输入30个字)