JSP query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cli
    New Member
    • Dec 2007
    • 9

    #1

    JSP query

    Hi Guys,

    I want to read a parameter from my query string and display it in my JSP page.
    e.g. "Results for your query JSP Query returned 10 results."
    I am using the following JSP code to grab the parameter from my querystring
    Code:
    String queryStr = (String) request.getParameter("querystr")
    All works fine unless someone searches for a piece of text which contains a script tag. Instead of displaying the script tag the page attempts to execute the code.

    I attempted to fix this by using :
    Code:
    URLEncoder.encode(queryStr);
    Now the code is not be executed but it is displaying the encoded charaters
    e.g Results for your search query
    Your search for %3Cscript%3Eale rt%28%22hello%2 2%29%3B%3C%2Fsc ript%3E returned 0 results.

    Can anyone tell me how to prevent this from happening?
    Thanks in advance.
  • NaftoliGug
    New Member
    • Aug 2008
    • 13

    #2
    String has a function to to a find/replace. So replace every < with &lt; and every > with &gt; (actually once you replaced the <s it might be unnecessary to replace > - try it.)

    Comment

    Working...