创建HttpServlet的基本步骤
A.导入包:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
B.继承HttpServlet类:
public class ××× extends HttpServlet
C.覆盖doPost()、doGet()方法:
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException{…}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException{…}
D.获取请求参数:
String param1 = request.getParameter();
E.创建输出对象:
PrintWriter out = response.getWriter();
F.设置响应类型:
response.setContentType();
G.输出响应内容:
out.println();
来自:http://blog.csdn.net/pengpenglin