Dowemo

The things that tomcat perform is: To initiate a connection to the server, accept the request sent by the browser, respond to the browser 's request, close the connection

First, you need to know what the servlet is, and why you can run it on the web without requiring a main function in your new class.

A servlet is a java application running on the server side that generates dynamic web. Don't need the main function to run, because the reflection mechanism of java is used to generate a servlet object in tomcat to generate a servlet object, such as.

Show code demo


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


//TODO Auto-generated method stub


//response.getWriter().append("Served at:").append(request.getContextPath());


 String name = request.getParameter("username");


 System.out.println(name);



 response.setContentType("text/html");


 PrintWriter pw = response.getWriter();


 pw.println("<div>hobby<ul><li>swimming</li><li>play game</li></ul></div>");


//pw.println("<span><p>Hello</p></span>");


//pw.println(str);


 pw.flush();


 pw.close();


 }





In the doget ( ) method above, the httpservletrequest method mentioned above is the same as the HttpServletResponse implementation method, and the reflection mechanism through java. The former is the packet sent by the browser, which is the response packet. The code mentioned above is simply a demonstration.

A form property is available on the browser to submit the properties of the entire form through the submit button, followed by request. Getparmeter ("name"), where name is the name attribute of the label in the form. This method can get the data in the browser sending form form.

Response request, sending packet to browser, this is a process that writes data to the packet by calling the input/output stream in java. Io. So a simple b development is done.


At the end, there's a lot of on the new.






Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs