Java Servlets   «Prev 

HelloWorld code for Java Servlet

What does the code for the HelloWorld Servlet look like?

Java Servlet used to generate HTML (as was done back in 1999, 2000)
Java Servlet used to generate HTML (as was done back in 1999, 2000)

lines 1, 2 and 3 import statements to permit short class names
line 5 define the servlet class
lines 7, 8 define the doGet method and its two parameters
line 9 list the exceptions this method might throw
line 11 set the content of the response to “text/html”
line 13 create an output writer attached to the response
line 15 write HTML to the output writer. It will reach the browser eventually
lines 17-20 continue writing HTML to the output writer
line 21 close the output writer