| | |
filtering bad user input
![]() |
•
•
Join Date: Mar 2004
Posts: 7
Reputation:
Solved Threads: 0
I am trying to set up a jsp page which takes input from any form and filters out user input which may pose a security risk. I am using the following function to try to do this:
I get a null pointer from the following line:
Been working at the computer for too long and going kinda bugeyed - so any other eyes that check this out are much appreciated!
Thanks in advance,
Dave.
Java Syntax (Toggle Plain Text)
<%! private String checkInput(String test){ String bad_input = ""; boolean someBadInput = false; char[] bad_characters = {'<','>','\'','\"','*','#','=','&','\\',';',':'}; int number_of_bad_characters = 11; int i; for(i=0; i<number_of_bad_characters; i++){ if(test.indexOf(bad_characters[i]) != -1){ if(!someBadInput){ bad_input += bad_characters[i]; someBadInput = true; }else{ if(i < (number_of_bad_characters-1)){ bad_input += ", "+ bad_characters[i]; }else{ bad_input += ", and "+ bad_characters[i]; } } } } if(someBadInput){ return bad_input; }else{ return "good"; } } %>
Java Syntax (Toggle Plain Text)
if(test.indexOf(bad_characters[i]) != -1){
Thanks in advance,
Dave.
•
•
Join Date: Mar 2004
Posts: 7
Reputation:
Solved Threads: 0
Wow, this is embarassing - the form I was submitting to the page had a spelling mistake inthe name of a field - so the page was trying to "request.getParameter("non_existant_parameter");" and passing a null pointer into the function. Sometimes you just need some sleep and or do something else for awhile....
Thanks to everyone who looked at the code. Sorry for the inconvienance.
Dave.
Thanks to everyone who looked at the code. Sorry for the inconvienance.
Dave.
![]() |
Similar Threads
- Tutorial: User Input: Strings and Numbers [C] (C)
- get user input for filename to open (C++)
- Type Conversion of User Input: (C++)
- Error Checking for user input (Java)
- error checking of user input (C++)
- user input into a string (C++)
- Creating a GUI that accepts user input help (Java)
- Need Help With Error Checking User Input (C)
Other Threads in the Java Forum
- Previous Thread: help? trying to compare input with symbol.
- Next Thread: Entering through mulitple Textfields
| Thread Tools | Search this Thread |
2dgraphics @param account affinetransform android api apple applet application arc arguments array automation banking binary binarytree bluetooth chatprogramusingobjects class client code color compare component count database derby design detection eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image inheritance integer j2me java java.xls javadesktopapplications javaprojects jlabel jni jpanel julia keytool keyword linux list macintosh map method methods midlethttpconnection mobile monitoring netbeans nullpointerexception object open-source pong problem producer program project projectideas property reference replaysolutions ria rim scanner server set size sms sourcelabs splash sql swing terminal threads transforms tree ui unicode validation web windows





