JSP - getParameter

Posted on 2002-04-24
Last Modified: 2011-09-20

I pass a variable from one page to another.

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


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
Question by:barnarp
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
LVL 19

Accepted Solution

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=" +"1%");

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

remember URL parameters are case sensitive.


Expert Comment

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


Expert Comment

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.
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!

LVL 19

Expert Comment

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.


Author Comment

ID: 6968611
Thank you.

All is fine now.

LVL 19

Expert Comment

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

Author Comment

ID: 6968741
no problem

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HashTable highest marks enumeration alternative 9 47
Is there a simpler dropbox system? 10 44
Bot application - advice 3 58
Java Inheritance super keyword use 8 32
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

740 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