练习 过滤用户输入的敏感字
Posted 厂公
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了练习 过滤用户输入的敏感字相关的知识,希望对你有一定的参考价值。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <form action="NewFile3.jsp" method="post"> <input type="text" name="name"> <input type="submit" value="提交"> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% String n=request.getAttribute("name1").toString(); %> <input type="text" value="<%=n%>"> </body> </html>
package com.hanqi.web; 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; public class TestFilter1 implements Filter { public TestFilter1() { } public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String str=request.getParameter("name"); String str1=str.replaceAll("的", "*"); request.setAttribute("name1", str1); System.out.println(str1); chain.doFilter(request, response); } public void init(FilterConfig fConfig) throws ServletException { } }
<filter> <display-name>TestFilter1</display-name> <filter-name>TestFilter1</filter-name> <filter-class>com.hanqi.web.TestFilter1</filter-class> </filter> <filter-mapping> <filter-name>TestFilter1</filter-name> <url-pattern>/NewFile3.jsp</url-pattern> </filter-mapping>
以上是关于练习 过滤用户输入的敏感字的主要内容,如果未能解决你的问题,请参考以下文章
Java基础练习题7--猜拳游戏,模拟双色球功能,统计词语次数,判断大写字母,敏感词过滤程序