gpt4 book ai didi

java - 在 JSP 页面中收到的变量值为 null

转载 作者:塔克拉玛干 更新时间:2023-11-01 23:10:00 29 4
gpt4 key购买 nike

<分区>

我做了一个简单的登录应用程序。但是每当发送表单时,servlet 都会收到空数据。

下面是登录页面

<body>
<form action="login">
Enter login Name : <input type="text" name="userName"/><br/>
Enter password : <input type="password" name="userPassword"/><br/>
<input type="submit" value="Log In"/>
</form>

下面是检查输入变量值的servlet代码

@WebServlet("/login")
public class loginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public loginServlet() {
super();
// TODO Auto-generated constructor stub
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = (String)request.getAttribute("userName");
String password = (String)request.getAttribute("userPassword");

System.out.print("in doGet method");
System.out.print(name+" "+password+" are these");


if(name!=null && password!=null){
System.out.print("in null method");
if(name=="admin" && password=="admin"){
// Cookie cookie = new Cookie("userName", name);
// response.addCookie(cookie);
// RequestDispatcher dispatch = request.getRequestDispatcher("success.jsp");
// dispatch.forward(request, response);

response.sendRedirect("success.jsp");
}
else{
System.out.print("in error method");
response.sendRedirect("error.jsp");
}
}
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}

我正在使用 System.out.print 方法在 Tomcat 控制台中打印值。

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com