【Servlet学习】继承HttpServlet简单示例
1 package com.sprying;
2 import java.io.IOException;
3 import java.io.PrintWriter;
4
5 import javax.servlet.http.HttpServlet;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 /**
10 *第三种方法开发servlet
11 *通过继承HttpServlet,
12 */
13 public class HttpExample extends HttpServlet
14 {
15 /**
16 *
17 */
18 private static final long serialVersionUID = 1L;
19 public void doGet(HttpServletRequest req,HttpServletResponse res)
20 {
21 this.doPost(req,res);
22 }
23 public void doPost(HttpServletRequest req,HttpServletResponse res)
24 {
25 try
26 {
27 PrintWriter pw=res.getWriter();
28 pw.print("HelloWorld,extends of HttpServlet");
29 }catch(IOException e)
30 {
31 e.printStackTrace();
32 }
33 }
34 }
有任何问题,欢迎留言交流。
注意:已解决的问题,会在整理后删除掉。
*******站在巨人的肩膀上