package temp;
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;
public class GetAndPostExample extends HttpServlet {
/**
* Constructor of the object.
*/
public GetAndPostExample() {
super();
}
/**
* Destruction of the servlet.
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet.
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* The doPost method of the servlet.
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String data = "";
String temp = "";
temp = (String) request.getParameter("firstName");
data = data + "第一个名字" + temp;
temp = (String) request.getParameter("middleName");
data = data + " 中间的名字" + temp;
temp = (String) request.getParameter("birthday");
data = data + " 生日" + temp;
temp = (String) request.getParameter("timeStamp");
data = data + " 调用时间" + temp;
System.out.println("获得的数据 " + data);
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
out.println(data);
out.flush();
out.close();
}
/**
* Initialization of the servlet.
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> This is the description of my J2EE component This is the display name of my J2EE component GetAndPostExample temp.GetAndPostExample