0

我正在尝试创建一个允许用户输入 unqiue ID 的登录屏幕。如何将信息传递给所选 ID 不唯一的用户。到目前为止,我所能做的就是触发异常。

注册.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Enter Your details here</title>
</head>
<body>
<h3>Enter User ID</h3>
<br>
<form action = "RegistrationServlet" method = "post">
Enter User ID : <input type = "text"  name ="newUserId"/>
<br>Enter your Password : <input type = "password" name ="newUserPassword"/>
<br>Enter your First Name :<input type = "text" name = "newUserFirstName"/>
<br>Enter your Last Name : <input type = "text" name ="newUserLastName"/>
<br><input type = "submit"/>
<br>
<%=session.getAttribute("notUniqueUserID")%>
</form>
</body>
</html>

注册服务小程序

catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            boolean notUniqueUserID = true;
            request.getSession(notUniqueUserID);
            response.sendRedirect("registration.jsp");
        }
4

1 回答 1

0

这不是最好的解决方案,因为它会重新加载表单并且用户需要再次输入所有数据,我建议您使用 AJAX 进行这种验证。无论如何,这里有一段代码为请求设置一个属性并在jsp中获取它。

小服务程序:

}catch (SQLException e) {
            e.printStackTrace();
            boolean notUniqueUserID = true;
            request.setAttribute("notUniqueUserID", "Not Unique User ID");
            request.getRequestDispatcher("registration.jsp").forward(request, response);
        }

JSP:

<%=request.getAttribute("notUniqueUserID")%>
于 2013-05-29T07:42:50.897 回答