What I'm trying to do here is to redirect to an html page with a form from servlet and as I redirect, is it possible to set values in a textfield of that form? Like the way I get the values from the form using request.getAttribute(), similarly is there a way to set values in a input element in an html form from a servlet? Would greatly appreciate your help, thank you.
Asked
Active
Viewed 368 times
0
-
can you explain why you want to do this? – NAK Nov 23 '17 at 04:38
-
You can use jsp page instead of html. Then you can create dynamic pages easily. – Tejendra Nov 23 '17 at 04:39
-
The requirement is to make this using html only but I'm not sure if it cannot be in html, that's why i got here, and as of why I'm doing this, I'm creating a web page form where user can register from a registration form and submit the details. And if the user wants to edit, then the user is redirected to the same registration page with his old details in the textboxes. – Nov 23 '17 at 04:46
1 Answers
2
Java does not provide method to set parameters in servlet. If you must do this using HTML here are two options:
(I still recommend using JSP)
1.display the registration page using PrintWriter#println()
in servlet.
response.setContentType("text/html");
out.println("blah blah blah");
out.println("<input name='username' type='text' value='"+javaVariable+"'");
out.println("blah blah blah");
2.In your HTML page make an AJAX call to servlet that returns data you need and populate form elements with this data.

NAK
- 478
- 2
- 9
-
Great, I'm not familiar with AJAX, but at least I got to know that there's a solution for it, will surely learn it, thanks a lot! :) – Nov 24 '17 at 05:21