过滤器链实现中文转码和文字屏蔽功能(4)
//chain.doFilter(req, resp);
}
}
[java]
package com.mars.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
public class WordFilter implements Filter {
private FilterConfig config = null;
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req=(HttpServletRequest)request;
HttpServletResponse resp=(HttpServletResponse)response;
String title = req.getParameter("title");
String content = req.getParameter("content");
title = title.replace("张", "李");
content = content.replace("剑桥", "****");
req.setAttribute("title", title);
req.setAttribute("content", content);
chain.doFilter(request, response);
}
public void destroy() {
config = null;
}
}
[java]
package com.mars.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MessageServlet extends HttpServlet {
相关新闻>>
- 发表评论
-
- 最新评论 更多>>