1. 程式人生 > >編寫處理請求引數的 Servlet

編寫處理請求引數的 Servlet

編寫處理請求引數的 Servlet,程式碼如下:

package servlet;

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class CheckParamServlet  extends HttpServlet{

/**

 *

 */

private static final long serialVersionUID = 1L;

 

public void doGet(HttpServletRequest request,

 HttpServletResponse response)

 throws ServletException, IOException {

 String name = request.getParameter("name");

 String pass = request.getParameter("pass");

 response.setContentType("text/html;charset=gb2312");

 PrintWriter out = response.getWriter();

 

 out.println("<html><head><title>Param Test</title></head>");

 out.println("<h3 align=center>你的使用者名稱為:"+name+"</h3>");

 out.println("<h3 align=center>你的口令為:"+pass+"</h3>");

 out.println("</body></html>");

 }

 

 public void doPost(HttpServletRequest request,

 HttpServletResponse response)

 throws ServletException, IOException {

 

 doGet(request,response);

 }

}