标签:
service
method
package cn.dragon.servlet; //下面是导入相应的包 import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * 这是第一个Servlet的例子 * @author cn.dragon */ public class ServletDemoFirst extends HttpServlet { //用于处理客户端发送的GET请求 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=GB2312"); //这条语句指明了向客户端发送的内容格式和采用的字符编码. PrintWriter out = response.getWriter(); out.println(" 您好!"); //利用PrintWriter对象的方法将数据发送给客户端 out.close(); } //用于处理客户端发送的POST请求 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); //这条语句的作用是,当客户端发送POST请求时,调用doGet()方法进行处理 } } |
以下截取部分 <servlet>
【注意】 ① 上面的两个<servlet-name>必须相同
|
package cn.dragon.servlet; import java.io.IOException; import javax.servlet.ServletException; public class ServletDemoSecond extends HttpServlet {
web.xml文件 <?xml version="1.0" encoding="UTF-8"?> |
标签:
原文地址:http://www.cnblogs.com/maociyuan/p/5198620.html