views:

45

answers:

1

Hi All,

I got a situation to transfer values from jsp to servlet's action class. Previously we did it using

<input type="hidden" id="name" value="manoj" />

we take this value in action class by request.getParameter("name"). But now we couldn't pass value like

"Hi\n
 i am\n 
 Manoj". 

Since it has new line included in the string we couldn't take it like this to action. So how I can take value like this to action or is there any way other than hidden input?

Thanks .

+1  A: 

You have to escape the newline character if you want to include it from a hidden input field. You can either escape the field value using html character code references or URL encoding the field value.

The value for a new line should be &#10; and for a carriage return &#13;

Other alternatives are

  • You could save the value of the parameter as to a session attribute or to a cookie and not pass it as a http parameter at all
  • You could include the value in a textarea that is hidden using CSS
  • You could include the value somewhere else in the document and include it to the form during the onsubmit handler (yuck)
Aleksi
In text area, even though i typed as multi line, i getting it as single line in action. I want to get as a typed
Manoj
Could you provide more context on what is happening and what are the results?
Aleksi
Sorry,it is working. Can you help me regarding URL Encoding. ?
Manoj
Congratulations! I recommend you create another question so we work like this site should work. I'd also be grateful if you would accept my answer if it worked or desribe your solution for those who stumble on the same problem.
Aleksi