我正在尝试在登录时使用 Javascript 和 JSP 实现警报提示,但我看不到成功。到目前为止,我所拥有的只是一条错误消息,我想将其作为提示。请帮忙。这就是我所拥有的:
小服务程序端:
String userValidate = logindao.authenticateUser(loginbean);
if(userValidate.equals("SUCCESS")){
request.setAttribute("userName", userName);
request.getRequestDispatcher("/Home.jsp").forward(request, response);
}else{
request.setAttribute("errMessage", userValidate);
request.getRequestDispatcher("/Login.jsp").forward(request, response);
}
我的 JSP 方面:
<td><%=(request.getAttribute("errMessage") == null)
? ""
: request.getAttribute("errMessage")%></td>
我的道:
public class LoginDao {
public String authenticateUser(LoginBean loginbean){
String userName = loginbean.getUserName();
String password = loginbean.getPassword();
Connection conn = null;
String userNameDB = "";
String passwordDB = "";
DBConnection db = new DBConnection();
try{
conn = db.getDbConnection();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT USER_NAME, P_WORD, WORK_CLASS FROM USER_LOGIN "
+ "where USER_NAME = '" + userName + "'");
while(rs.next()){
userNameDB = rs.getString("USER_NAME");
passwordDB = rs.getString("P_WORD");
}
if(userName.equalsIgnoreCase(userNameDB)&& password.equalsIgnoreCase(passwordDB)){
return "SUCCESS";
}
if(userName.equals("") || password.equals("")){
return "Username or Password is blank";
}
}catch(Exception asd){
System.out.println(asd);
}
return "invalid user credentials";
}
}
如果证书有误,我得到的只是页面上打印的错误消息。我怎样才能将其作为提示?