A) What is a servlet?
Servlet (server-side applet) is a server-side program written in the Java language [O1], which can be used to generate dynamic Web pages using scripting languages.
b) The schema of the servlet?
- Also the server schema is sprinkled.
- The location of the servlet in the WEB application
c) The task of the servlet?
- Read client (browser) data:
- an explicit [O2] Httl request data (HTML form on a Web page, or it can be a form from an applet or a custom HTTP client program)
- . implicit [O3] HTTP request data (cookies, media types, compression formats that the browser can understand, and so on)
- Process data and generate results
- Send data (that is, documents) to the client (browser)
d) MyEclipse tool operation Servlet
1. Create a Web server project,
2. Create a new package,
3. Create a new servlet file,
4. Change the path in Web. XML "This is very important!" "
5.run as (My Eclipse application)"NOTE: see if the project is deployed HA"
6. Look at the port number:
Info: Starting Coyote http/1.1 on http-8080
7. Access in the browser: 192.168.2.19 is host
Http://192.168.2.19:8080/MyWebSeverProject/MyServlet
What is printed in the browser: This is class Cn.com.fs.test01.MyServlet, using the GET method
"Note: The servlet file has not been changed again and requires a reboot"
8. Note Several statements in the servlet:
(1) public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
Parameters: Request: Contains client requests information response set the information returned by the service side
(2) Response.setcontenttype ("text/html");//Set the format of the returned content
(3) PrintWriter out = Response.getwriter (); The Printin method of the PrintWriter object can be interpreted as directly returning data
(4) Out.flush ();//Refresh--Transfer data all the time
(5) Out.close ();//close--data transfer complete, end
[O1]
- Vip
- Web Development
[O2] Look at the code to understand
[O3] such as compression format Zip,rar
Build a Web server on MyEclipse