| import javax.servlet.*; |
| import javax.servlet.annotation.WebFilter; |
| import javax.servlet.annotation.WebInitParam; |
| import javax.servlet.http.HttpServletRequest; |
| import javax.servlet.http.HttpServletRequestWrapper; |
| import java.io.IOException; |
| |
| import java.io.IOException; |
| |
| |
| @WebFilter(filterName = "WordFilter",urlPatterns = "/MessageServlet",initParams ={ |
| @WebInitParam(name="encoding",value = "UTF-8") |
| } ) |
| public class WordFilter implements Filter { |
| |
| private String words[]; |
| |
| private String encoding; |
| @Override |
| public void init(FilterConfig filterConfig) throws ServletException { |
| |
| encoding = filterConfig.getInitParameter("encoding"); |
| |
| words= new String[]{"糟糕","混蛋"}; |
| |
| } |
| |
| @Override |
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { |
| |
| if (encoding != null){ |
| |
| request.setCharacterEncoding(encoding); |
| |
| request= new Request((HttpServletRequest) request); |
| |
| response.setContentType("text/html;charset="+encoding); |
| |
| }chain.doFilter(request,response); |
| } |
| |
| @Override |
| public void destroy() { |
| Filter.super.destroy(); |
| this.words = null; |
| this.encoding = null; |
| } |
| |
| class Request extends HttpServletRequestWrapper{ |
| |
| public Request(HttpServletRequest request) { |
| super(request); |
| } |
| |
| |
| @Override |
| public String getParameter(String name) { |
| return filter(super.getParameter(name)); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| } |
| |
| public String filter(String param){ |
| try{ |
| |
| if (words != null && words.length > 0){ |
| |
| for (int i = 0; i < words.length; i++) { |
| |
| if (param.indexOf(words[i])!=-1){ |
| |
| param = param.replaceAll(words[i], "****"); |
| } |
| } |
| } |
| }catch (Exception e){ |
| e.printStackTrace(); |
| } |
| return param; |
| } |
| } |
| import javax.servlet.ServletException; |
| import javax.servlet.annotation.WebServlet; |
| import javax.servlet.http.HttpServlet; |
| import javax.servlet.http.HttpServletRequest; |
| import javax.servlet.http.HttpServletResponse; |
| import java.io.IOException; |
| |
| @WebServlet(name = "MessageServlet",urlPatterns = "/MessageServlet") |
| public class MessageServlet extends HttpServlet { |
| @Override |
| protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
| |
| String title = req.getParameter("title"); |
| |
| String content = req.getParameter("content"); |
| |
| req.setAttribute("title", title); |
| |
| req.setAttribute("content", content); |
| |
| req.getRequestDispatcher("wordFilter.jsp").forward(req,resp); |
| } |
| |
| } |
| <%-- |
| Created by IntelliJ IDEA. |
| User: Administrator |
| Date: 2024/4/24 |
| Time: 9:45 |
| To change this template use File | Settings | File Templates. |
| --%> |
| <%@ page contentType="text/html;charset=UTF-8" language="java" %> |
| <html> |
| <head> |
| <title>意见反馈</title> |
| <style type="text/css"> |
| body { |
| margin: 0px; |
| font-size: 12px; |
| } |
| td{ |
| font-size: 12px; |
| } |
| .div1{ |
| width: 1003px; |
| height: 707px; |
| background-image: url("images/bg.jpg"); |
| } |
| .div2{ |
| width: 500px; |
| margin-top:245px; |
| margin-left:180px; |
| text-align:left; |
| } |
| .tl{ |
| width: 500px; |
| height: 20px; |
| font-weight: bold; |
| background: #A3C0C6; |
| padding: 5px; |
| } |
| .ct{ |
| width: 500px; |
| padding-left: 30px; |
| padding-top: 5px; |
| padding-bottom: 5px; |
| } |
| .tt{ |
| margin-left:5px; |
| width: 70px; |
| background: #A3C0C6; |
| padding: 5px; |
| font-weight: bold; |
| font-size: 13px; |
| } |
| </style> |
| </head> |
| |
| <body> |
| <div align="center"> |
| <div class="div1"> |
| <div class="div2"> |
| <% |
| String title = (String) request.getAttribute("title"); |
| String content = (String)request.getAttribute("content"); |
| if(title != null && !title.isEmpty()){ |
| out.println("<span class='tl'>" + title + "</span>"); |
| } |
| if(content != null && !content.isEmpty()){ |
| out.println("<span class='ct'>" + content + "</span>"); |
| } |
| %> |
| <span class="tl">谢谢你们</span> |
| <span class="ct">你们的公司服务态度非常好,谢谢你们!</span> |
| <span class="tl">谢谢你们</span> |
| <span class="ct">你们的公司服务态度非常好<br>但部分客服服务态度还要加强!</span> |
| <form action="MessageServlet" method="post"> |
| <span class="tt">意见反馈</span> |
| <table border="0" width="500" align="center"> |
| <tr> |
| <td align="right">标 题:</td> |
| <td><input type="text" name="title" size="30"></td> |
| </tr> |
| <tr> |
| <td align="right">内 容:</td> |
| <td> |
| <textarea rows="5" cols="40" name="content"></textarea> |
| </td> |
| </tr> |
| <tr> |
| <td align="center" colspan="2"> |
| <input type="submit" value="提 交"> |
| </td> |
| </tr> |
| </table> |
| </form> |
| </div> |
| </div> |
| </div> |
| |
| </body> |
| </html> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)