struts2添加过滤器后乱码 本来页面没有乱码 为什么添加了 过滤器之后就乱码了、过滤器 有 首先是汉字乱码过滤 然后是 登录过滤 最后是权限过滤 怎么回事 不适用过滤器 就不会出现乱码 ……………… 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 乱码过滤器protected String encoding = null; protected FilterConfig filterConfig = null; protected boolean ignore = true; public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; this.encoding = filterConfig.getInitParameter("encoding"); String value = filterConfig.getInitParameter("ignore"); if (value == null) this.ignore = true; else if (value.equalsIgnoreCase("true")) this.ignore = true; else this.ignore = false; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // TODO 自动生成方法存根 if (ignore || (request.getCharacterEncoding() == null)) { String encoding = selectEncoding(request); if (encoding != null) request.setCharacterEncoding(encoding); } chain.doFilter(request, response); }xml配置:<filter> <filter-name>Set Character Encoding</filter-name> <filter-class>team4.motor.action.SetCharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>Set Character Encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 登录过滤器public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; HttpSession session = request.getSession(); PrintWriter out=response.getWriter(); if (session.getAttribute("manager") == null||session.getAttribute("carowner") == null||session.getAttribute("operator") == null) { out.print("<script language=javascript>alert('请登录');javascript:location='../index.jsp'</script>"); } chain.doFilter(req, res); }xml配置:<filter> <filter-name>loginFilter</filter-name> <filter-class>team4.motor.action.LoginFilter</filter-class> </filter> <filter-mapping> <filter-name>loginFilter</filter-name> <url-pattern>/operator/*</url-pattern> <url-pattern>/manager/*</url-pattern> </filter-mapping> 权限过滤public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { // 获取uri地址 HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; HttpSession session = request.getSession(); String uri = request.getRequestURI(); String ctx = request.getContextPath(); uri = uri.substring(ctx.length()); PrintWriter out = response.getWriter(); if (uri.startsWith("/manager")) { if (session.getAttribute("manager") == null) { out.print("<script language=javascript>alert('can not goto');javascript:history.go(-2)</script>"); } } if(uri.startsWith("/operator")){ if(session.getAttribute("operator")==null){ out.print("<script language=javascript>alert('can not goto');javascript:history.go(-2)</script>"); } } chain.doFilter(req, res); }xml配置:<filter> <filter-name>priorityFilter</filter-name> <filter-class>team4.motor.action.PriorityFilter</filter-class> </filter> <filter-mapping> <filter-name>priorityFilter</filter-name> <url-pattern>/manager/*</url-pattern> <url-pattern>/operator/*</url-pattern> <url-pattern>/carowner/*</url-pattern> </filter-mapping> Email 问题??? 哈哈,这个东西怎么搞啊 急、急、急request.getParameter()问题 <content>问题 救命 很急!!! 求助 各位高手帮我看一看这是怎么会事?十分感谢!!! jsp朋友能在这里留下QQ号吗? 急!急!急!求大神解答,Servlet.service() for servlet jsp threw exception servlet包的问题 求助一个小型的门户网站如何实现!!!! 如何调用其它系统的页面
protected FilterConfig filterConfig = null;
protected boolean ignore = true; public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else
this.ignore = false;
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO 自动生成方法存根
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
chain.doFilter(request, response);
}xml配置:
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>team4.motor.action.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession();
PrintWriter out=response.getWriter();
if (session.getAttribute("manager") == null||session.getAttribute("carowner") == null||session.getAttribute("operator") == null) {
out.print("<script language=javascript>alert('请登录');javascript:location='../index.jsp'</script>");
}
chain.doFilter(req, res);
}xml配置:
<filter>
<filter-name>loginFilter</filter-name>
<filter-class>team4.motor.action.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>loginFilter</filter-name>
<url-pattern>/operator/*</url-pattern>
<url-pattern>/manager/*</url-pattern>
</filter-mapping>
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
// 获取uri地址
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession();
String uri = request.getRequestURI();
String ctx = request.getContextPath();
uri = uri.substring(ctx.length());
PrintWriter out = response.getWriter();
if (uri.startsWith("/manager")) {
if (session.getAttribute("manager") == null) {
out.print("<script language=javascript>alert('can not goto');javascript:history.go(-2)</script>");
}
}
if(uri.startsWith("/operator")){
if(session.getAttribute("operator")==null){
out.print("<script language=javascript>alert('can not goto');javascript:history.go(-2)</script>");
}
}
chain.doFilter(req, res);
}xml配置:
<filter>
<filter-name>priorityFilter</filter-name>
<filter-class>team4.motor.action.PriorityFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>priorityFilter</filter-name>
<url-pattern>/manager/*</url-pattern>
<url-pattern>/operator/*</url-pattern>
<url-pattern>/carowner/*</url-pattern>
</filter-mapping>