Solved

JSP - getParameter

Posted on 2002-04-24
7
873 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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:
Suggested Courses

626 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