HTML form generator servlet

Example-Html form generator servlet package itso.servjsp.servletapi; import java.io.*; import javax.servlet.*; import javax.servlet.htt...


Example-Html form generator servlet
package itso.servjsp.servletapi;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HTMLFormGenerator extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
System.out.println("In the init() method of HTMLFormGenerator");
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
performTask(req, res, "POST",
"itso.servjsp.servletapi.HTMLFormHandler");
// "/itsoservjsp/servlet/itso.servjsp.servletapi.HTMLFormHandler");
}
public void performTask(HttpServletRequest req, HttpServletResponse res,
String method, String url) throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><TITLE>HTMLFormGenerator</TITLE><BODY>");
out.println("<H2>Servlet API Example - HTMLCreatingServlet</H2><HR>");
out.println("<FORM METHOD=\"" + method + "\" ACTION=\"" + url + "\">");
out.println("<H2>Tell us something about yourself: </H2>");
out.println("<B>Enter your name: </B>");
out.println("<INPUT TYPE=TEXT NAME=firstname><BR>");
out.println("<B>Select your title: </B>");
out.println("<SELECT NAME=title>");
out.println("<OPTION VALUE=\"Web Developer\">Web Developer");
out.println("<OPTION VALUE=\"Web Architect\">Web Architect");
out.println("<OPTION VALUE=\"Other\">Other");
out.println("</SELECT><BR>");
out.println("<B>Which tools do you have experience with: </B><BR>");
out.println("<INPUT TYPE=checkbox NAME=\"tools\"
VALUE=\"WebSphere Application Server\">WebSphere Application Server<BR>");
out.println("<INPUT TYPE=checkbox NAME=\"tools\"
VALUE=\"WebSphere Studio\">WebSphere Studio<BR>");
out.println("<INPUT TYPE=checkbox NAME=\"tools\"
VALUE=\"VisualAge for Java\">VisualAge for Java<BR>");
out.println("<INPUT TYPE=checkbox NAME=\"tools\"
VALUE=\"IBM Http Web Server\">IBM Http Web Server<BR>");
out.println("<INPUT TYPE=checkbox NAME=\"tools\" VALUE=\"DB2 UDB\">DB2 UDB<BR>");
out.println("<INPUT TYPE=\"SUBMIT\" NAME=\"SENDPOST\" NAME=\"SENDPOST\">");
out.println("</FORM>");
out.println("</BODY><HTML>");
out.close();
System.out.println("In the doGet method");
}
}

init method

This servlet implements the init method. The init method only prints a message to standard output and call the super-class constructor. As we mentioned before, the init method is called only once, when the servlet is loaded. This message, therefore, should only be printed to the Web server’s console or log once (wherever standard output is defined), regardless of how many times the servlet is actually invoked.

doGet method

We decided that this servlet is always called through a GET request, we have chosen to implement the doGet method, instead of the more generic service method. We developed a performTask method to which we pass a method posting type and a target URL.

Response object

The HTML page that this servlet generates is a bit more complex than the previous example. It actually builds an HTML form that can be used in the future to call other servlets. This is not the same as a servlet calling a servlet, which is a server-side process, Here, we are just using one servlet to generate the HTML back to the browser, so we can call our other example servlets, and we do not have to create separate HTML files for each servlet. Notice that this servlet has many out.println statements. This is just the HTML that is written back to the browser. Despite the size of this servlet, it is still only doing one simple thing, writing HTML output.
Name

ADO,131,ASP,3,C++,61,CORE JAVA,1,CSS,115,HTML,297,index,5,JAVASCRIPT,210,OS,47,PHP,65,SAD,53,SERVLETS,23,SOFTWARE ENGINEERING,245,SQL,71,TCP/IP,1,XHTML,9,XML,18,
ltr
item
Best Online Tutorials | Source codes | Programming Languages: HTML form generator servlet
HTML form generator servlet
Best Online Tutorials | Source codes | Programming Languages
https://www.1000sourcecodes.com/2012/05/html-form-generator-servlet.html
https://www.1000sourcecodes.com/
https://www.1000sourcecodes.com/
https://www.1000sourcecodes.com/2012/05/html-form-generator-servlet.html
true
357226456970214079
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content