import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.Enumeration; public class FormServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(""); out.println(""); out.println(""); out.println("Form Examples"); out.println(""); out.println(""); String formType = request.getParameter("formtype"); if(formType == null) { Enumeration e = request.getParameterNames(); out.println("

Parameter and Return Data from previous form

"); out.println("
"); if(!e.hasMoreElements()) { out.println("None"); } while(e.hasMoreElements()) { String name = (String)e.nextElement(); out.println(name + ": " + request.getParameter(name)); out.println("
"); } out.println("

Select the form to see an example and view html source:

"); out.println("
"); out.println("

"); out.print("

"); out.println(""); out.println("Text Form"); out.println("
"); out.println(""); out.println("Password Form"); out.println("
"); out.println(""); out.println("Checkbox Form"); out.println("
"); out.println(""); out.println("RadioForm"); out.println("
"); out.println(""); out.println("Reset Form"); out.println("
"); out.println(""); out.println("Selection Form"); out.println("
"); out.println(""); out.println("Text Area Form"); out.println("
"); out.println(""); } else if(formType.equals("textform")) { out.println("

Text Form

"); out.println("
"); out.println("

"); out.print(""); out.println("Text Field Label"); out.println(""); out.println("
"); out.println(""); out.println("
"); out.println("
"); out.println("<P>"); out.println("
"); out.print("<form action=\""); out.print("ServletName\" "); out.println("method=GET>"); out.println("
"); out.println("Text Field Label"); out.println("
"); out.println("<input type=text name=textfield value=default>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<input type=submit>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("</form>"); } else if(formType.equals("passwordform")) { out.println("

Password Form

"); out.println("
"); out.println("

"); out.print(""); out.println("Password Field Label"); out.println(""); out.println("
"); out.println(""); out.println("
"); out.println("
"); out.println("<P>"); out.println("
"); out.print("<form action=\""); out.print("ServletName\" "); out.println("method=GET>"); out.println("
"); out.println("Password Field Label"); out.println("
"); out.println("<input type=password name=passwordfield value=default>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<input type=submit>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("</form>"); } else if(formType.equals("checkboxform")) { out.println("

Checkbox Form

"); out.println("
"); out.println("

"); out.print(""); out.println(""); out.println("Checkbox Field Label"); out.println("
"); out.println(""); out.println("
"); out.println("
"); out.println("<P>"); out.println("
"); out.print("<form action=\""); out.print("ServletName\" "); out.println("method=GET>"); out.println("
"); out.println("<input type=checkbox name=checkboxfield value=default>"); out.println("
"); out.println("Checkbox Field Label"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<input type=submit>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("</form>"); } else if(formType.equals("radioform")) { out.println("

Radio Form

"); out.println("
"); out.println("

"); out.print(""); out.println(""); out.println("Radio Field Label1"); out.println("
"); out.println(""); out.println("Radio Field Label2"); out.println("
"); out.println(""); out.println("Radio Field Label3"); out.println("
"); out.println(""); out.println("
"); out.println("
"); out.println("<P>"); out.println("
"); out.print("<form action=\""); out.print("ServletName\" "); out.println("method=GET>"); out.println("
"); out.println("<input type=radio name=radiofield value=option1>"); out.println("
"); out.println("Radio Field Label1"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<input type=radio name=radiofield value=option2>"); out.println("
"); out.println("Radio Field Label2"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<input type=radio name=radiofield value=option3>"); out.println("
"); out.println("Radio Field Label3"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<input type=submit>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("</form>"); } else if(formType.equals("resetform")) { out.println("

Reset Form

"); out.println("
"); out.println("

"); out.print(""); out.println("Text Field Label"); out.println(""); out.println("
"); out.println(""); out.println(""); out.println("
"); out.println("
"); out.println("<P>"); out.println("
"); out.print("<form action=\""); out.print("ServletName\" "); out.println("method=GET>"); out.println("
"); out.println("Text Field Label"); out.println("
"); out.println("<input type=text name=textfield value=default>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<input type=submit>"); out.println("
"); out.println("<input type=reset>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("</form>"); } else if(formType.equals("selectionform")) { out.println("

Selection Form

"); out.println("
"); out.println("

"); out.print(""); out.println(""); out.println("
"); out.println(""); out.println("
"); out.println("
"); out.println("<P>"); out.println("
"); out.print("<form action=\""); out.print("ServletName\" "); out.println("method=GET>"); out.println("
"); out.println("<select name=\"listname\">"); out.println("
"); out.println("<option>first option"); out.println("
"); out.println("<option>second option"); out.println("
"); out.println("<option>third option"); out.println("
"); out.println("</select>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<input type=submit>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("</form>"); } else if(formType.equals("textareaform")) { out.println("

Textarea Form

"); out.println("
"); out.println("

"); out.print(""); out.println(""); out.println("
"); out.println(""); out.println("
"); out.println("
"); out.println("<P>"); out.println("
"); out.print("<form action=\""); out.print("ServletName\" "); out.println("method=GET>"); out.println("
"); out.println("<textarea name=\"text area name\" rows=5 cols=80>Default text goes here"); out.println("
"); out.println("</textarea>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<input type=submit>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("<br>"); out.println("
"); out.println("</form>"); } out.println("

"); out.println(""); out.println(""); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } }