0

How can I give value of HTML hidden field with spaces? Here i have used used string q to store y ques, suppose, what is 2 +2? And here the value of hidden field named 'q' is passed as only 'what'.

<%String q = request.getParameter("que"); 
out.print(q);
          out.print("<form action='postAns' method='post'>"+
            "<input type='hidden' name='que' value="+q+">" +"<br>"+
            "<input type='text' name='ans' >"+
            "<input type='submit' value='post'>"+
        "</form>");
%>

How can i get whole string for the value of 'que' in HTML form which is forwarded to postAns.java servlet? Even i used setAttribute but for jsp it is setting up properly. Can anyone help in sorting out this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sophia
  • 145
  • 2
  • 12
  • @DanielGale But i am taking input from user this question. So how can i add this %20 in my string? Because i wont know what the 'q' is when i use this: String q = request.getParameter("que"); – Sophia Apr 16 '18 at 17:10
  • in javascript there is an `encodeURI()` method. This may help: https://coderanch.com/t/579827/java/jsp-request-parameter-string-white – Daniel Gale Apr 16 '18 at 17:22
  • @DanielGale thanks,it may help. – Sophia Apr 16 '18 at 17:37

0 Answers0