當一個servlet接收來自客戶端的調用請求, 它接收兩個對象: 一個是ServletRequest,另外一個是ServletResponse. 這個ServletRequest class 概括從客戶端到服務器之間的聯系, 而 ServletResponse class 概括從servlet返回客戶端的聯系.
ServletRequest interface 可以獲取到這樣一些信息如由客戶端傳送的闡述名稱,客戶端正在使用的協議, 產生請求并且接收請求的服務器遠端主機名. 它也提供獲取數據流的servlet, ServletInputStream, 這些數據是客戶端引用中使用HTTP POST 和 PUT 方法遞交的. 一個ServletRequest的子類可以讓servlet獲取更多的協議特性數據. 例如: HttpServletRequest 包含獲取HTTP-specific頭部信息的方法.
// 用一個thank you返回客戶端 toClient.println("<html>"); toClient.println("<title>Thank you!</title>"); toClient.println("Thank you for partictoClient.println("</html>");
} catch(IOException e) { e.printStackTrace(); toClient.println( "A problem occured while recording your answers. " + "Please try again."); }
public void doPost( catch (InterruptedException e) { } } }
提供關于Servlet的信息
/** * This is a simple example of an HTTP Servlet. It responds to the GET * and HEAD methods of the HTTP protocol. */ public class SimpleServlet extends HttpServlet {
...
public String getServletInfo() { return "A simple servlet"; } }進入討論組討論。