Solved

JSP - getParameter

Posted on 2002-04-24
7
865 Views
Last Modified: 2011-09-20
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
Comment
Question by:barnarp
7 Comments
 
LVL 19

Accepted Solution

by:
cheekycj earned 50 total points
ID: 6965545
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
 
LVL 2

Expert Comment

by:coreyit
ID: 6967525
You can also try (in page 1):
<%=response.encodeURL( "http://localhost:8080/HandleSearch.jsp?searchstr=1%" )%>

-corey
0
 

Expert Comment

by:jodear
ID: 6967652
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 19

Expert Comment

by:cheekycj
ID: 6968602
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
 

Author Comment

by:barnarp
ID: 6968611
Thank you.

All is fine now.

Regards
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6968617
Glad I could help.  Thanx for the "A"
0
 

Author Comment

by:barnarp
ID: 6968741
no problem
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question