Servlet之初识
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 }
Servlet之初识的更多相关文章
- [Servlet] 初识Servlet
什么是Servlet? 定义 Servlet的全称是 Server Applet,顾名思义,就是用 Java 编写的服务器端程序. Servlet 是一个 Java Web开发标准,狭义的Servle ...
- 初识Servlet
1.创建DispatcherServlet package myservlet; import java.io.IOException; import javax.servlet.ServletExc ...
- 初识Jsp,JavaBean,Servlet以及一个简单mvc模式的登录界面
1:JSP JSP的基本语法:指令标识page,include,taglib;page指令标识常用的属性包含Language用来定义要使用的脚本语言:contentType定义JSP字符的编码和页面响 ...
- Servlet初识
1.servlet的生命周期 servlet生命周期中的三大重要时刻 servlet从不存在状态迁移到初始化状态(能够为客户提供服务),首先是从构造函数开始,但是构造函数只是使其成为一个对象,而不是一 ...
- 初识JAVA,对servlet的理解
一.WEB开发的简单理解 Web开发是一个指代网页或站点编写过程的广义术语.网页使用 HTML.CSS 和 JavaScript编写.这些页面可能是类似于文档的简单文本和图形.页面也能够是交互式的,或 ...
- servlet学习总结(一)——初识Servlet
Servlet工作过程 当客户端向web服务器发送servlet请求时,web服务器首先检查是否已经加载并创建了servlet实例对象.如果没有会装载并创建该Servlet的一个实例对象.然后调用se ...
- [Servlet&JSP] 初识ServletContext
ServletContext是整个Web应用程序运行后的代表对象,能够通过ServletConfig的getServletContext()方法来取得,之后就能够利用ServletContext来取得 ...
- 初识Java Servlet
Java Servlet是什么? Servlet的本质就是一个Java接口,之所以能生成动态的Web内容,是因为对客户的一个HTTP请求,Servlet通过接口这个规范重写了其中的方法,然后Web服务 ...
- Servlet(二):初识Servlet
在手动写完一个Servlet小例子后,是不是有很多疑问,接下来会为大家详细介绍Servlet的知识. 1.什么是Servlet 是在服务器上运行的小程序.一个servlet就是一个Java类,并且可以 ...
随机推荐
- 深入了解 Dojo 的服务器推送技术
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
- Hadoop on Mac with IntelliJ IDEA - 3 解决MRUnit - No applicable class implementing Serialization问题
本文讲述在IntelliJ IDEA中使用MRUnit 1.0.0测试Mapper派生类时因MapDriver.withInput(final K1 key, final V1 val)的key参数被 ...
- stl lower_bound upper_bound binary_search equal_range
自己按照stl实现了一个: http://www.cplusplus.com/reference/algorithm/binary_search/ 这里有个注释,如何判断两个元素相同: Two e ...
- 得到内网域管理员的5种常见方法<转>
1.Netbios and LLMNR Name Poisoning 这个方法在WIN工作组下渗透很有用,WIN的请求查询顺序是下面三个步骤:本地hosts文件(%windir%\System32\d ...
- 【M20】协助完成“返回值优化(RVO)”
1.方法返回对象,会导致临时对象的产生,这降低了效率,const Rational operator* (const Rational& lhs,Rational& rhs).有没有什 ...
- 我所经历的SAP选型
这是一个失败的选型项目,而且在可遇见的未来公司也不会再经历SAP选型,甚至不会再启动erp项目,个中原因很难一言道尽,在此简要的说说我们的选型过程以及在选型过程中对各种因素的考虑. 一.重启选型工作七 ...
- STM8的wait for interrupt
如果我用disable interrupt和enable interrupt包裹wait forinterrupt(WFI).你说WFI还能被唤醒么?有思考过么? 昨晚拿STM8L151K4的开发板, ...
- Android编译提示ImportError: No module named bz2的解决办法
在安装node.js时提示ImportError: No module named bz2.很明显这个python中没有装bz2的库导致的.解决方法:sudo apt-get install libb ...
- 怎样拷贝整个目录并且忽略部分文件及目录(包括windows)
http://www.dewen.org/q/2150 rsync -a --exclude dir1 --exclude dir2 ... source target
- android138 360 小火箭
package com.itheima52.rocket; import android.app.Service; import android.content.Context; import and ...