| | |
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
- user input into a string (C++)
- 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++)
- 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 |
account android api applet application array arrays automation bidirectional binary birt bluetooth class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program project property recursion ria scanner search server set sharepoint smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree unlimited webservices windows





