浏览器输入后台能够获取user_name的值但是user_pwd的值显示为null
package edu.zut.controller;
import edu.zut.dao.UserDao;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class UserLoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
String user_name = request.getParameter("user_name");
String user_pwd = request.getParameter("user_pwd");
System.out.println("user_name = " + user_name);
System.out.println("user_psw = " + user_pwd);
String error;
if (null == user_name || user_name.trim().length() == 0 || null == user_pwd || 0 == user_pwd.trim().length()){
error = "姓名或密码不能为空";
request.setAttribute("error",error);
RequestDispatcher dispatcher = request.getRequestDispatcher("/loginPage");
dispatcher.forward(request, response);
}else {
UserDao userDao = new UserDao();
boolean result = userDao.userLogin(user_name, user_pwd);
System.out.println(result);
if (result){
request.setAttribute("user_name",user_name);
request.getRequestDispatcher("/indexPage").forward(request,response);
}else {
error = "用户名或密码不正确";
request.setAttribute("error",error);
request.getRequestDispatcher("/loginPage").forward(request,response);
}
}
}
}
登录界面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>
<form action="../userLogin" method="get">
<input type="text" name="user_name" placeholder="请输入用户名"><br>
<input type="password" name="user_pwd" placeholder="请输入密码"><br>
<input type="submit" value="登录">
</form>
</body>
</html>