title: How to fill the html form in jsp with the dispatched data from servlet?
body: <p>I am new to JSP and Servlet. I need your suggestion in following task.
  I have a jsp page which hava a html form which accepts some information from user.</p>
  
  <p>JSP page
  info.jsp</p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;%
      if(request.getAttribute("reply")!=null){
          out.println(request.getAttribute("reply"));
      }
  %&gt;
  
  &lt;form action="actionservlet" method="post" name="myform"&gt;
  user Name:&lt;input name="username" type="text" size="10" /&gt;&lt;br /&gt;
  First Name:&lt;input name="username" type="text" size="10" /&gt;&lt;br /&gt;
  Last Name:&lt;input name="username" type="text" size="10" /&gt;&lt;br /&gt;
  Email id:&lt;input name="username" type="text" size="10" /&gt;&lt;br /&gt;
  &lt;input name="submit" type="submit" value="Submit" /&gt;
  &lt;input name="Reset" type="reset" value="Reset" /&gt;
  
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>As this client enters information and submits the form the data in the form is set to actionservlet which check whether the username entered by user
  is already exists in database. If username already exists then it sends the data back to the calling jsp and with an extra attribute that is "reply" and value as 
  appropriate message. i.e. "user already exists " if entered user name is already exists in database or "user information saved successfully!" if data saved successfully.</p>
  
  <p>I want to do something like that Whenever the username which is already exists is entered by user and form submitted then in this case the all data send back to the jsp 
  should be get fill to their respective textbox. So that user can only enter the other username and submit this form again.
  How to achieve the above task.</p>
  
  <p>I am thinking of adding jsp scriplet to value property of each textbox and check that whether this replay message. if the reply message is regarding 
  duplicate username then it should assign the value to value property else the value property will remain empty. But I think that this solution is not optimum 
  because as the number of fields will increases in the form this solution will get little bit tedious. And also I think due to this the it give rise to some 
  sort of redundant code.
      So I want to ask experts that is there any other way to do the same. I want to fill the form only when the error or duplicate message comes and not 
  when success message comes.</p>
  
  <p>Thank You!</p>