跪求强大的敏感字过滤源码 做个娱乐网站,求大虾们有强大的敏感字过滤的源码的给个!本人不胜感激 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不是吧还得花钱买啊??难道没有开源的那种JAR包? 我自己写过一个用于论坛上的敏感词过滤实现,Wu-Manber匹配算法。要的话可以email发给你。 多谢了我的email:[email protected] 我也想要 [email protected] 谢谢了 我也想要 [email protected] 天啊你们都来凑热闹了?哈哈,多谢各位的好意,我已经找到个很强大的过滤的JAR包了,还能自定义过滤,还具有过滤的过滤等级! 发一个自己做的过滤器,注释里面写了一些测试数据://敏感词汇过滤器public class WordsFilter implements Filter { //下面三个集合记住的是都是用于匹配用户提交数据的正则表达式 private List<String> banWords = new ArrayList(); //禁用词 婊.{2}子 你是一个婊 子 private List<String> auditWords = new ArrayList(); //审核词 private List<String> replaceWords = new ArrayList(); //替换词 public void init(FilterConfig filterConfig) throws ServletException { try{ String path = WordsFilter.class.getClassLoader().getResource("/").getPath(); File file = new File(path); File files[] = file.listFiles(); for(File f : files){ if(!f.getName().endsWith(".txt")){ continue; } BufferedReader br = new BufferedReader(new FileReader(f)); String line = null; while((line=br.readLine())!=null){ if(line.trim().equals("")){ continue; } String values[] = line.trim().split("\\|"); //[换妻,1] if(values.length!=2){ continue; } if(values[1].trim().equals("1")){ banWords.add(values[0]); } if(values[1].trim().equals("2")){ auditWords.add(values[0]); } if(values[1].trim().equals("3")){ replaceWords.add(values[0]); } } } }catch (Exception e) { throw new RuntimeException(e); } } public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) resp; HttpServletRequest request = (HttpServletRequest) req; //1.检查用户提交的数据中是否包含禁用词 Enumeration e = request.getParameterNames(); while(e.hasMoreElements()){ String inputName = (String) e.nextElement(); String inputValue = request.getParameter(inputName); //***姨子**** if(inputValue==null || inputValue.trim().equals("")){ continue; } //用禁用词库去检查用户的输入 for(String regex: banWords){ Pattern p = Pattern.compile(regex); Matcher m = p.matcher(inputValue); if(m.find()){ //代表用户输入的数据有和正则表达式相匹配的数据 request.setAttribute("message", "文章中包含非法词汇,请文件用语!!!"); request.getRequestDispatcher("/message.jsp").forward(request, response); return; } } } //程序运行到此,意味着用户提交的数据没有包含禁用词 request.getPrameter(""); chain.doFilter(new MyRequest(request), response); //servlet myrequest.getParameter("resume") } class MyRequest extends HttpServletRequestWrapper{ private HttpServletRequest request; public MyRequest(HttpServletRequest request) { super(request); this.request = request; } @Override public String getParameter(String name) { String inputData = this.request.getParameter(name); //你就是个杂种,你的妈妈说你就是?? if(inputData==null){ return null; } //对用户输入的数据进行审核词的替换 for(String regex : auditWords){ Pattern p = Pattern.compile(regex); Matcher m = p.matcher(inputData); if(m.find()){ String data = m.group(); //得到用户数据中,与正则表达式匹配的数据 inputData = inputData.replaceAll(regex, "<font color='red'>"+data+"</font>"); //你就是个<font color='red'>杂种</font>,你说你是吗?? } } //对用户输入的数据进行替换词的替换 for(String regex : replaceWords){ Pattern p = Pattern.compile(regex); Matcher m = p.matcher(inputData); if(m.find()){ inputData = inputData.replaceAll(regex, "****"); //你就是个<font color='red'>杂种</font>,你说你是吗?? } } return inputData; } } public void destroy() { // TODO Auto-generated method stub } } 想请教个问题。 关于ssh加载信息显示问题... 如何测试weblogic 的ForeignServer的连接情况? jsp问题 网站流量统计问题 急啊~~ spring问题 <jsp:forward page="portal" />这里的portal对应哪里? spring web应用中,调用bean 插入数据库的问题 STRUTS1.0 升级到 1.1的问题. 各位,启动tomcat的时候报了这个错误,牛人帮我看一下哦。谢谢了 struts中调用接口时候的Cannot make a static reference to the non-static method问题
要的话可以email发给你。
public class WordsFilter implements Filter { //下面三个集合记住的是都是用于匹配用户提交数据的正则表达式
private List<String> banWords = new ArrayList(); //禁用词 婊.{2}子 你是一个婊 子
private List<String> auditWords = new ArrayList(); //审核词
private List<String> replaceWords = new ArrayList(); //替换词
public void init(FilterConfig filterConfig) throws ServletException {
try{
String path = WordsFilter.class.getClassLoader().getResource("/").getPath();
File file = new File(path);
File files[] = file.listFiles();
for(File f : files){
if(!f.getName().endsWith(".txt")){
continue;
}
BufferedReader br = new BufferedReader(new FileReader(f));
String line = null;
while((line=br.readLine())!=null){
if(line.trim().equals("")){
continue;
}
String values[] = line.trim().split("\\|"); //[换妻,1]
if(values.length!=2){
continue;
}
if(values[1].trim().equals("1")){
banWords.add(values[0]);
}
if(values[1].trim().equals("2")){
auditWords.add(values[0]);
}
if(values[1].trim().equals("3")){
replaceWords.add(values[0]);
}
}
}
}catch (Exception e) {
throw new RuntimeException(e);
}
}
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) resp;
HttpServletRequest request = (HttpServletRequest) req;
//1.检查用户提交的数据中是否包含禁用词
Enumeration e = request.getParameterNames();
while(e.hasMoreElements()){
String inputName = (String) e.nextElement();
String inputValue = request.getParameter(inputName); //***姨子****
if(inputValue==null || inputValue.trim().equals("")){
continue;
}
//用禁用词库去检查用户的输入
for(String regex: banWords){
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(inputValue);
if(m.find()){
//代表用户输入的数据有和正则表达式相匹配的数据
request.setAttribute("message", "文章中包含非法词汇,请文件用语!!!");
request.getRequestDispatcher("/message.jsp").forward(request, response);
return;
}
}
}
//程序运行到此,意味着用户提交的数据没有包含禁用词 request.getPrameter("");
chain.doFilter(new MyRequest(request), response); //servlet myrequest.getParameter("resume")
}
class MyRequest extends HttpServletRequestWrapper{ private HttpServletRequest request;
public MyRequest(HttpServletRequest request) {
super(request);
this.request = request;
}
@Override
public String getParameter(String name) {
String inputData = this.request.getParameter(name); //你就是个杂种,你的妈妈说你就是??
if(inputData==null){
return null;
}
//对用户输入的数据进行审核词的替换
for(String regex : auditWords){
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(inputData);
if(m.find()){
String data = m.group(); //得到用户数据中,与正则表达式匹配的数据
inputData = inputData.replaceAll(regex, "<font color='red'>"+data+"</font>"); //你就是个<font color='red'>杂种</font>,你说你是吗??
}
}
//对用户输入的数据进行替换词的替换
for(String regex : replaceWords){
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(inputData);
if(m.find()){
inputData = inputData.replaceAll(regex, "****"); //你就是个<font color='red'>杂种</font>,你说你是吗??
}
}
return inputData;
}
}
public void destroy() {
// TODO Auto-generated method stub } }