Reputation: 706
I am trying to pass variables from one jsp page to another and I am retrieving it through
s=request.getParameter("itemId");
The value of variable I am passing is :
<CAAD0KRhXaJ5FAuOxR760HBzgaD-_JyXoVAymeQf+nQdCawEgGA@mail.gmail.com>
when I pass my page address lokks likes this:
http://localhost:8080/Mazil-1.1.0/jsp/final.jsp?itemId=<CCAAD0KRhXaJ5FAuOxR760HBzgaD-_JyXoVAymeQf+nQdCawEgGA@mail.gmail.com>
But when I print this value on final.jsp it prints:
<CAAD0KRhXaJ5FAuOxR760HBzgaD-_JyXoVAymeQf [email protected]>
It replaces '+' by space .I don't know why it does that and how to correct it?
Upvotes: 0
Views: 82
Reputation: 325
I would suggest you to use it this way:
String encodedItemId = URLEncoder.encode("<CAAD0KRhXaJ5FAuOxR760HBzgaD-_JyXoVAymeQf+nQdCawEgGA@mail.gmail.com>","UTF-8");
And then submit url as:
http://localhost:8080/Mazil-1.1.0/jsp/final.jsp?itemId=encodedItemId
Then to retrieve the actual Item Id do as follow:
String decodedItemId = URLEncoder.encode(request.getParameter(itemId));
Upvotes: 1
Reputation: 6444
The parameter names and values specified should be left unencoded by the page author. The JSP container must encode the parameter names and values using the character encoding from the request object when necessary. For example, if the container chooses to append the parameters to the URL in the dispatchedrequest,boththenamesandvaluesmustbeencodedasperthecontent typeapplication/x-www-form-urlencoded in the HTML specification.
Upvotes: 0
Reputation: 5868
Put your value into session and than retrieve it whenever you need. Using urls for it is not recommended.
Upvotes: 0
Reputation: 7069
You can replace plus sign with %2B
before sending in URL.
You also can put it as an attribute in request like this
request.setAttribute("itemId","<CAAD0KRhXaJ5FAuOxR760HBzgaD-_JyXoVAymeQf+nQdCawEgGA@mail.gmail.com>");
in sender jsp.
And get in receiver jsp using request.setAttribute("itemId");
Upvotes: 0