2012 第2章 Java Servlet扩展和增强Web服务器.ppt
文本预览下载声明
Java Servlet;Outlines;Servlet Overview;Outlines;What is HTML;More about HTML ;Client/
Browser;HTTP Request and Response;Outlines;What Is a Servlet?;Example (1);Servlet generates an HTML response based on the input from the form. The Server returns the HTML document (response).;...
form action=/Music/SearchServlet method=POST
h3Music Store Search/h3brstrongType in the song title:/strong
input type=text size=55 name=song_titlebr
strongType in the song artist:/strong
input type=text size=55 name=song_artistbr
input type=submit value=SearchbrstrongDisplay the first /strong;POST /Music/SearchServlet HTTP/1.0
Referer: /musicSearch.html
Connection: Keep-Alive
User-Agent: Mozilla/4.72 [en] (WinNT 5.0; U)
Host: localhost:8080
Cookie: USERID=spot
Accept: image/gif, image/x-xbitmap, image/jpeg, */*
Accept-Language: en
Accept-Charset: iso-8859-1,*,utf-8
Content-type: application/x-www-form-urlencoded
Content-length: 50
song_title=Hellosong_artist=Joneslimit_number=20;HTTP/1.1 200 ok
Content-Type: text/html
Set-Cookie: sessionid=5H2HXGYAAAAAEWQAAAAZJCI;Path=/
Cache-Control: no-cache=set-cookie,set-cookie2
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Set-Cookie: USERID=spot;Expires=Fri, 08-Jun-2001 21:54:37 GMT
Content-Language: en
HTML
BODY
H1Very simple dynamic document created on 01-Jun-2001/H1
/BODY
/HTML;URL request
response;Outlines;Building a Simple Java Servlet;package com.ibm.example.servlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintWriter;
public class VerySimpleServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String browser = request.getHeader(User-Agent);
response.setStatus(HttpServletResponse.SC_OK); // default
response.setContentType(text/ht
显示全部