JSP forums for sensitive character type filter (to those有分)
Abstract: JSP forums for sensitive character type filter (to those有分)
I have a forum, for fear of others in the forums with a number of political and sexual things, I would like to add a filter, when the posts when found these sensitive words then prompt the user to return to re-fill. Do not know how to write? master their help!
Another dual want to prevent SQL injection for a type of filtering, URL filter out the incorrect characters, the two filters that one please help !!!!!!!!!!!!!!!! !
Servet Filter with the technology, it can play a role in filtering, you look at it, I have not been engaged in this
Help set ASP done before, which is Maple Leaf-injection procedures do not know no Java version of the Kazakhstan.
Character-judgement but it seems useful to other people can not fight Pinyin demolition of a mixed intermediate + hyphen. . . .
Support
Did not help me?
Top
Bangding
Looking for a more comprehensive FITER on it. . This code seems to be the Internet. Search under
Regularization
I used the FILTER, but it led to a lot of other issues, in the depressed ….
Up
Filter with the technology servet
Access points
Top
UP
Content2 / / the contents of the submission
Public static final String filter = "and developed the votes | 6th century | My name is named Xiao Liu were" / / characters to worry, with | segregation
Java.util.regex.Matcher m = java.util.regex.Pattern.compile (filter). Matcher (content2);
If (m.find ())
(
Out.println ( "content with using illegal characters (uncivil language, advertising, political topics or special symbols ).");
Return;
)
Really good question
Not realizing it, when people enter if adding other symbols such as underline, strikeout type what you that it is difficult to judge the bar.
Support
Public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
(
String tmp = request.getParameter ( "fieldName");
If (tmp.contains ( "pornographic text"))
Response.sendRedirect ( "rewrite.jsp");
Chain.doFilter (request, response);
)
Ah, servlet and can be used to do a regular expression,
You can be judged by whether or not the importation of characters including some illegal characters,
If yes, you can filter it filters out!
Or to ask it to re-fill!
Read everyone's opinion, I feel filter can be, but if the user is in the words and in a space / quotes / punctuation or anything like that, it is estimated on the powerless, some large sites you how they do it my problem in the depressed !!!!!!!!!!!!!!!!!!!!!!!
Difficult to engage many of the segmentation of the characters are middle
It is used!
In the java.util.regex package
But java in the "/" and "(" ")" must be coupled with the front of a backslash
Eg: (/ d (3)) / s / d (3) - / d (4)
In java: //(// d (3 }//)// s / / d (3) - / / d (4)
The use of filters
The risk replace all of the characters
I am of course aware of the need to filter characters, who wrote this thing? To share!
Finally to make every effort to fully Zaiding !!!!!!!!!!!!!!!!!
Bangniding!
My message is http://community.csdn.net/Expert/TopicView3.asp?id=4835599
Some experts dedicated to the posts, you can see
As a regular expression, and common FILTER I do not know how to do so hey to the top
Bangding!
Must use a filter is, but mainly in how to deal with illegal characters you can look into the regular expression, the landlord of the two issues are related and string handling, it should be can be solved by the regular expression
Learning …
UP
In a minute
Bangding about, waiting for a solution, with the knowledge and long, huh ….
Up
I do blog, they also met in the sensitive word filtering,
The best solution is to use a regular expression:
Basic wording:
String sentence, s sensitive word str word filtered into the sensitive *
Patter.complic Patter p = (string);
Matcher m = p.math (s);
Str = m.replaceAll ("*");
100% shielding is impossible. .
If people enter when adding other symbols such as underline, strikeout type what you that it is difficult to judge the bar.
To achieve such a good situation. .
Build a chapter! !
Top!
To those有分
(Public class RemoveText
Public static String [] getStringData (String str, String sign) (
StrData String [] = null;
StringTokenizer st1 = new StringTokenizer (str, sign);
StrData = new String [st1.countTokens ()];
Int i = 0;
While (st1.hasMoreTokens ()) (
StrData st1.nextToken [i] = (). Trim ();
I + +;
)
Return strData;
)
Public static boolean isBadwords (String str) (
Boolean result = false;
Str = str.toUpperCase ();
String badwords = "" bastard | phone | Advertising ";
String [] data = getStringData (badwords ,"|");
Int j = 0;
For (int i = 0; i
If (dot! =- 1) (
Result = true;
Return result;
)
)
Return result;
)
Public static void main (String [] args) (
String str = "mobile phone";
Boolean is isBadwords = (str);
System.out.println (is); / / returns that contained false negative terms
)
)
Thank you koma_wind ()
Bangding about, waiting for a solution, with the knowledge and long, huh …. I would also like to use this ah
Now that the problem has been largely resolved, but there are still a problem that is, if the user in the middle of the word sensitive, such as what symbol, it also Mozhe!!
Is not resolved, does not end with quote, Zaiding
There is no perfect solution
Iwlk (6th century http://down.c06.net) can be a
Good
UP
Filter SERVLET used in the filter type can be achieved.
Give you a whole! !
Public void doFilter (ServletRequest request, ServletResponse response
8., FilterChain filterChain)
9. (
10. Try
11. (
12. / / Request and the response of type conversion
13. HttpServletRequest httpRequest = (HttpServletRequest) request;
14. HttpServletResponse httpResponse = (HttpServletResponse) response;
15.
16. Boolean isValid = true;
17. String uriStr = httpRequest.getRequestURI (). ToUpperCase ();
18. If (uriStr.indexOf ( "LOGIN.JSP") == -1 & &
19. UriStr.indexOf ( "SWITCH.JSP") == -1 & &
20. HttpRequest.getSession (). GetAttribute ( "ses_userBean") == null)
21. (
22. IsValid = false;
23.)
24. If (isValid)
25. (
26. FilterChain.doFilter (request, response);
27.) Else
28. (
29. HttpResponse.sendRedirect ( "/ webModule / login.jsp");
30.)
31.
32.) Catch (ServletException sx)
33. (
34. FilterConfig.getServletContext (). Log (sx.getMessage ());
35.) Catch (IOException iox)
36. (
37. FilterConfig.getServletContext (). Log (iox.getMessage ());
38.)
39.)
Interception of string
What is this? This is the word filtering website and the correct hash code is not in line with that intention.
JF
Bangding
<%!
Public String strReplace (String str)
(
String replaceChr ="%";
String dChr = "25%";
String hasReplaced = "";
Boolean toReplace = true;
While (toReplace)
(
If (toReplace)
(
While (str.indexOf (replaceChr)! =- 1)
(
Str.substring hasReplaced + = (0, str.indexOf (replaceChr)) + dChr;
Str = str.substring (str.indexOf (replaceChr) +1, str.length ());
)
HasReplaced + = str;
Str = hasReplaced;
HasReplaced = "";
)
If (str.indexOf ("//")!=- 1)
(ReplaceChr ="//";
DChr = "% 5C% 5C";
Continue;
)
If (str.indexOf ("/"")!=- 1)
(ReplaceChr ="/"";
DChr = "% 5C% 22";
Continue;
)
If (str.indexOf ("=")!=- 1)
(ReplaceChr ="=";
DChr = "% 3D";
Continue;
)
If (str.indexOf ("+")!=- 1)
(ReplaceChr ="+";
DChr = "% 2B";
Continue;
)
If (str.indexOf ("/")!=- 1)
(ReplaceChr ="/";
DChr = "% 2F";
Continue;
)
If (str.indexOf ("?")!=- 1)
(ReplaceChr ="?";
DChr = "% 3F";
Continue;
)
If (str.indexOf ("#")!=- 1)
(ReplaceChr ="#";
DChr = "23%";
Continue;
)
If (str.indexOf ("&")!=- 1)
(ReplaceChr ="&";
DChr ="&";
Continue;
)
ToReplace = false;
)
Return str;
)
Public int strReplace (int i)
(Return i;
)
Public float strReplace (float f)
(Return f;
)
%>
D
Have to be totally unfounded, it is impossible.
If people in other words, insert text or symbols you it is very difficult to worry. It is not used to, you know how people in the characters inserted between several characters? If wildcard, then fix on unfounded wrong. Moreover, people will not use the word. People can understand that read, the computer how to understand?
Such as:
Law ※%% 'round "" "" credit ""
Jiangzhe people
That the reason that if say so, that is not the role of filtering little?
That the reason that if say so, that is not filtered There is not much meaning?
DDDDDDDDDDDDDDDDDDDDDDDDdd
As a regular expression filter
Ding
Bangniding
UP
Regularization
Top !!!!!
As a regular expression filter characters, such as Chinese characters left addition, all other concern swaps, and so on, and then judge
Good topic to support the continuation of the discussion
I encountered the same problem, and looks forward answer.
Ddd
Up
D
As a regular expression filter characters, such as Chinese characters left addition, all other concern swaps, and so on, and then judge
Agree with this
There was also a need sensitive words or phrases dictionary, by comparison
Let China so that the programmer is tired.
Up
You can define a new one. Txt file, you have to filter the characters are written on the inside, use the following procedure can be a filter.
Public void init (FilterConfig filterConfig)
(Throws ServletException
Try (
/ / Read sensitive Words List
File f = new File ("../ webapps / bbs / web-inf / words.txt ");
BufferedReader br = new BufferedReader (new FileReader (f));
Int count = 6;
Sub = new String [count];
For (int i = 0; i
)
) Catch (IOException e) (System.err.println (e);)
)
I only give up a part of you can write a Servlet.
TXT file inside the sensitive word what separated?
Build a chapter! !
To the very top
Favourites ~ ~ `
Help DDDDDing
What symbol of the middle class
Who will be found? I still could not believe the
Increasingly confused! Mozhe!
Write a word sensitive configuration file to use a regular expression matching
Not to engage in, and we should source? Who gave?
/ **
* Replacement for the sensitive character "***"
* @ Param s1 parameters 1, all the sensitive character set requirements format, "Jianren | idiots | You"
* @ Param s2 parameter 2 to filter string
* @ Return the string returned to filter
* /
Public String replace (String s1, String s2) (
String result = "";
Result = s2.replaceAll (s1 ,"***");
Return result;
)
Access points
Servet the Filter
I read everyone's opinions and feelings can not be 100% of the shielding, as in the middle of what keywords such symbols?
Right, not 100% shielding, and you know he wants to sign in the middle of what?
↑ Back
Tags: Character, forums, java filter
Releated Java Articles
April 19, 2007 | Filed Under API for Java |






