码迷,mamicode.com
首页 > 其他好文 > 详细

怎么获取表单数据

时间:2016-08-24 01:05:46      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!