Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 888
  • Last Modified:

JSP - getParameter

hi,

I pass a variable from one page to another.

the page I pass the variable to looks like this in the address bar:

http://localhost:8080/HandleSearch.jsp?searchstr=1%

the variable's value is "1%"

I run the following code:

String tosearchstr = request.getParameter("searchstr");

but get a null value every time for tosearchstr!

please help
0
barnarp
Asked:
barnarp
1 Solution
 
cheekycjCommented:
make sure the value of searchstr "1%" is url encoded

so when you pass it...

do this

String urlString = "http://localhost:8080/HandleSearch.jsp?HandleSearch.jsp?searchstr=" + java.net.URLEncoder.encode("1%");

to retrieve just do:
String tosearchstr = request.getParameter("searchstr");

remember URL parameters are case sensitive.

CJ
0
 
coreyitCommented:
You can also try (in page 1):
<%=response.encodeURL( "http://localhost:8080/HandleSearch.jsp?searchstr=1%" )%>

-corey
0
 
jodearCommented:
From experience, I'd prefer cheekycj's answer.  

The reason for URL encoding strings is because the percent sign (%) is a special character for URLs.  Other special characters are blank spaces, quotes, commas, dots, slash, question mark, semicolon, colon, equal sign, etc.  To be on the safe side, regard all characters that are not letters nor numerical as special characters in the URL thus its better to URL encode any string with those special characters.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
cheekycjCommented:
jodear: Why did you propose an answer and just agree with my comment?

Please refer to the bottom of this page for comments vs answers policies.

CJ
0
 
barnarpAuthor Commented:
Thank you.

All is fine now.

Regards
0
 
cheekycjCommented:
Glad I could help.  Thanx for the "A"
0
 
barnarpAuthor Commented:
no problem
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now