You are on page 1of 1

*Servlets

-all folders and files goes in the root directory. html documents goes i
n the root.
-the root folder is www
-navigate to workspace and src folder
-map to execution of program when bring up the program on a browser
-urlPatterns does this example
urlPatterns = {
"/examples/Hello" }
-put Java codes in WEB-INF classes folder. Put web.xml file in the WEB-I
NF.
-two servets with the same html coding on the server will not execute
-response we use to talk back to the client
-use web.xml for welcoming file list
response.setContentType("text/html");
response.getWriter().println("<h1>Hello");
content type sets how the browser reads the file.
Page load code instantiated servlet load init() executes once
service() and doxxx() methods executes every request.
Request Counter
Create a servlet
private static int count = 0
doGet(){
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
Copy html as comments
Copy and paste html code in print statements. Use \ to escape qu
otation makes. Put it in front of
quotation marks.
Note: Close tags as soon as you open them.
Copy and paste default html structure into the out.println("");
out.println(++count);
You can share memory over a servlet.

You might also like