<form>
. . .
<div class="loginDiv">
<%= new java.util.Date() %>
<br/><br/>
Username : <input type="text" class="resizedTextbox" name="username">
Password : <input type="text" class="resizedTextbox" name="password">
<input type="submit" name="btnLogin" value="LogIn">
<a href="register.jsp">Register</a>
</div>
</form>
<%
if(request.getAttribute("btnLogin") != null){
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username != "" && password != ""){
out.print("Invalid Username/Password!");
}
else{
out.print("Invalid Username/Password!");
}
}
%>
我放置了一个断点,当我点击btnLogin时,request.getAttribute(“btnLogin”)中的代码永远不会被调用。 为什么会这样?
答案 0 :(得分:1)
尝试这样做:
if(request.getParameter("username") != null && request.getParameter("password") != null)
而不是:
if(request.getAttribute("btnLogin") != null){
答案 1 :(得分:0)
<form action="Call this Login page here (eg: Login.jsp)" method="post">
<div class="loginDiv">
<%= new java.util.Date()%>
<br/><br/>
Username : <input type="text" class="resizedTextbox" name="username">
Password : <input type="text" class="resizedTextbox" name="password">
<input type="submit" name="btnLogin" value="LogIn">
<a href="register.jsp">Register</a>
</div>
</form>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
if (username != "" && password != "") {
} else {
out.print("Invalid Username/Password!");
}
%>