过滤器的正确打开方式

原创 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;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

过滤器的正确打开方式

xml version="1.0" encoding="UTF-8"?>web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xm...

正确的打开“方法”!

二维数组的使用和方法的重载与可变长参数

精选:深入理解 Docker 内部原理及网络配置

网络绝对是任何系统的核心,对于容器而言也是如此。Docker 作为目前最火的轻量级容器技术,有很多令人称道的功能,如 Docker 的镜像管理。然而,Docker的网络一直以来都比较薄弱,所以我们有必要深入了解Docker的网络知识,以满足更高的网络需求。

Xcode 的正确打开方式——Debugging

程序员日常开发中有大量时间都会花费在 debug 上,从事 iOS 开发不可避免地需要使用 Xcode。这篇博客就主要介绍了 Xcode 中几种能够大幅提升代码调试效率的方式。 “If debugg...

Xcode 的正确打开方式——Debugging

程序员日常开发中有大量时间都会花费在 debug 上,从事 iOS 开发不可避免地需要使用 Xcode。这篇博客就主要介绍了 Xcode 中几种能够大幅提升代码调试效率的方式。 “If debu...

Xcode 的正确打开方式——Debugging

http://www.cocoachina.com/ios/20150225/11190.html 程序员日常开发中有大量时间都会花费在 debug 上,从事 iOS 开发不可避免地...
  • xyxjn
  • xyxjn
  • 2015-02-26 09:45
  • 483

Activity--onSaveInstanceState正确的打开方式

背景之所以会写这篇文章,是因为之前偶然看见csdn的博客专家写到这个问题,给出的结论实在让人大跌眼镜。于是看了下源码,索性做个记录。在Android 7.0以前,谷歌一直约束着让它以单窗口的姿态与广大...

Xcode 的正确打开方式——Debugging

程序员日常开发中有大量时间都会花费在 debug 上,从事 iOS 开发不可避免地需要使用 Xcode。这篇博客就主要介绍了 Xcode 中几种能够大幅提升代码调试效率的方式。 “If debu...

Activity的正确打开方式

本文来自稀土掘金翻译计划的投稿,Liz 同学翻译,是这几天掘金上的热文。主题比较基础但是写得不错,越是基础的东西有时候越是需要清晰掌握,相信会对一些同学有帮助,推荐给还没看过的同学阅读。

Xcode 的正确打开方式——Debugging

程序员日常开发中有大量时间都会花费在 debug 上,从事 iOS 开发不可避免地需要使用 Xcode。这篇博客就主要介绍了 Xcode 中几种能够大幅提升代码调试效率的方式。 “If debu...

Pull Request的正确打开方式

GitHub的官方帮助如下: Fork A Repo: https://help.github.com/articles/fork-a-repoUsing Pull Requests: http...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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