注意<form action="q" method="post">里边的method是post,在servlet里边相应的就调用doPost方法,然后在调用doGet方法
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// doPost(request, response);
response.setContentType("text/html;charset=UTF-8");
//String title = "用户登录";
// 接收HTML页面上的表单内容。
String name =request.getParameter("name");
String passwd = request.getParameter("password");
System.out.println("UserName:"+name+";"+"PassWord:"+passwd);
//获取数据库里对应名字的密码,getSqlPw(String); 与数据库的交互获取密码
String sqlPw = getSqlPw(name);
//将数据写回
PrintWriter out = response.getWriter();
if(sqlPw==null)
sqlPw = "NULL";
out.write(sqlPw); //sqlPw为xml数据
out.close();
}