Solved

JSP - getParameter

Posted on 2002-04-24
7
853 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groovy example issue 10 87
Java - Why doesn't this JFrame work 3 40
Apps blocked by Java 9 55
diffSum example 4 19
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

937 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

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now