Servlet之初识
2024-09-12 19:41:14
doHeader 用于处理HEADER请求
doGet 用于处理GET请求,也可以自动的支持HEADER请求
doPost 用于处理POST请求
doPut 用于处理PUT请求
doDelete 用于处理DELETE请求
1 package org.caiduping.Servlet;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5
6 import javax.servlet.ServletException;
7 import javax.servlet.http.HttpServlet;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10
11 public class Servlet extends HttpServlet {
12
13 /**
14 * Constructor of the object.
15 */
16 public Servlet() {
17 super();
18 }
19
20 /**
21 * Destruction of the servlet. <br>
22 */
23 public void destroy() {
24 super.destroy(); // Just puts "destroy" string in log
25 // Put your code here
26 }
27
28 /**
29 * The doGet method of the servlet. <br>
30 *
31 * This method is called when a form has its tag value method equals to get.
32 *
33 * @param request the request send by the client to the server
34 * @param response the response send by the server to the client
35 * @throws ServletException if an error occurred
36 * @throws IOException if an error occurred
37 */
38 public void doGet(HttpServletRequest request, HttpServletResponse response)
39 throws ServletException, IOException {
40
41 response.setContentType("text/html");
42 PrintWriter out = response.getWriter();
43 out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
44 out.println("<HTML>");
45 out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
46 out.println(" <BODY>");
47 out.print(" This is ");
48 out.print(this.getClass());
49 out.println(", using the GET method");
50 out.println(" </BODY>");
51 out.println("</HTML>");
52 out.flush();
53 out.close();
54 }
55
56 /**
57 * The doPost method of the servlet. <br>
58 *
59 * This method is called when a form has its tag value method equals to post.
60 *
61 * @param request the request send by the client to the server
62 * @param response the response send by the server to the client
63 * @throws ServletException if an error occurred
64 * @throws IOException if an error occurred
65 */
66 public void doPost(HttpServletRequest request, HttpServletResponse response)
67 throws ServletException, IOException {
68
69 response.setContentType("text/html");
70 PrintWriter out = response.getWriter();
71 out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
72 out.println("<HTML>");
73 out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
74 out.println(" <BODY>");
75 out.print(" This is ");
76 out.print(this.getClass());
77 out.println(", using the POST method");
78 out.println(" </BODY>");
79 out.println("</HTML>");
80 out.flush();
81 out.close();
82 }
83
84 /**
85 * Initialization of the servlet. <br>
86 *
87 * @throws ServletException if an error occurs
88 */
89 public void init() throws ServletException {
90 // Put your code here
91 }
92
93 }
最新文章
- SqlCommand执行带GO的SQL脚本文件
- oc获得相册照片
- python os.system()返回值判断
- Power Gating的设计(概述)
- poj3525Most Distant Point from the Sea(半平面交)
- HDU 4351 Digital root 线段树区间合并
- Hibernate从入门到精通(四)基本映射
- mkimage使用详解
- 【C语言探索之旅】 第二部分第八课:动态分配
- MSBuild Tools解决办法
- python 中 reduce 函数的使用
- c# error
- c/c++ 继承与多态 文本查询的小例子(智能指针版本)
- javascript 之 数组
- 使用Microsoft自带的小工具将可执行文件(.exe)注册为系统服务
- C#.NET 中的 Timer 计时器及 3 种使用方法
- Python全栈学习_day004作业
- 把文本数据转化为json
- 开始转型学习java
- asp mvc @Html.CheckBox(";sel";,true) 往后台传值问题