标签:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//获取表单数据
/**
* Servlet implementation class GetFormSrevlet
*/
@WebServlet("/GetFormSrevlet.do")
public class GetFormSrevlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GetFormSrevlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 设置请求表单数据支符集编码
request.setCharacterEncoding("UTF-8");
// 获取表单数据
String name =request.getParameter("userName");
String passWord =request.getParameter("passWord");
String sex =request.getParameter("sex");
// 设置响应内容字符集编码
response.setCharacterEncoding("UTF-8");
// 设置响应内容字符集编码
response.setContentType("text/html");
// 获取响应流
PrintWriter out= response.getWriter();
// 填写响应正文 显示在页面上
out.println("<html>");
out.println("<head>");
out.println("<title>返回内容</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>"+name+"</h1>");
out.println("<h1>"+passWord+"</h1>");
out.println("<h1>"+sex+"</h1>");
out.println("/<body>");
out.println("/<html>");
out.close();
}
}
标签:
原文地址:http://www.cnblogs.com/sdswl/p/5801204.html