现在的位置: 首页 > 综合 > 正文

servlet做用户管理之一

2013年12月19日 ⁄ 综合 ⁄ 共 1329字 ⁄ 字号 评论关闭

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.*;
import javax.servlet.http.*;
public class helloword3 extends HttpServlet{
 //客户端用get方式访问页面时就是调用了doGet方法(直接在地址栏里面敲url地址)!
 //客户提交表单,并且表单用post方式提交时,调用了doPost方式!
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  doPost(req,resp);
 }

 @Override
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  resp.setCharacterEncoding("utf-8");
  //.在servlet中输出中文,如果采用PrintWriter方式,需要在调用getPrintWriter()之前调用
  //setContentType或者 setCharacterEncoding;采用ServletOutputStream方式,不受此限。
  PrintWriter pw = resp.getWriter();
  pw.print("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'/><title>无标题文档</title></head><body>");
  pw.print("<h1>用户登录</h1><br/>");
  pw.print("<form id='form1' name='form1' method='post' action='login'>");
  pw.print("用户名:<input type=password id='userName' name='userName'><br>");
  pw.print("密码:<input type=password id='pwd' name='pwd'><br>");
  pw.print("<input type=checkbox id='check' name='check'>两周之内不需要登录<br/>");
  pw.print("<input type=submit value='提交'>");
  pw.print("</from></body></html>");
 }
 
}

抱歉!评论已关闭.