• Post Reply Bookmark Topic Watch Topic
  • New Topic

reading URL parameters in jsp

 
payal Jain
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I am trying to read the parameters passed in URL through jsp.
But when i read them i get the blank value.
my URL is http://localhost:9090/MyTomcat/firstjsp.jsp?bgColor=#FDF5E6.
and my code
String bgColor = request.getParameter("bgColor");
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The # sign is a special character and needs to be encoded.
 
payal Jain
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you tell me how to encode these special characters(#&),what code i need to add so that I can get the result.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever creates the URL needs to URL encode the values. Just how depends upon where the URL is being generated.
 
Paritosh Ranjan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.encodeURL("yourURL") does the work of encoding your URL in a correct form.Just check whether it can help with #.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Response.encodeUrl doesn't escape characters.
Its purpose is to embed the sessionId in the URL when session cookies are not enabled.

Look at java.net.URLEncoder.
If used correctly, that will escape the necessary characters.
You will still need to understand when and when not to encode characters or you'll end up encoding control characters that need to be left alone.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!