我有一个用于用户注册的HTML表单,如下所示。我想检查用户输入的两个密码,如果它们不匹配,我想显示 errorpage.html 错误消息。但是在我写完两个密码后,它会重定向到我的UserInfo Servlet,而不显示错误消息。除非两个密码都相同,否则我不希望它重定向到我的Servlet。除非两个密码相同,否则有人可以建议一种方法来保持在同一JSP页面上吗? 预先谢谢你。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>User Registration</title>
<%@ include file="Header.html" %>
</head>
<body>
<form action = "UserInfo" method ="POST">
<input type="hidden" name="user" value="signup">
<h3 >Sign Up</h3><br>
Name: <input type="text" name="name" required><br>
Surname: <input type="text" name="sname" required><br>
Password: <input type="password" name="password" required><br>
Re-enter password: <input type="password" name="password2" required><br>
<input type="submit" value="Sign Up">
</form>
<% String pass1 = request.getParameter("password");
String pass2 = request.getParameter("password2");
if (pass1!=null && pass2!=null) {
if (!pass1.equals(pass2)) {
%>
<%@ include file="errorpage.html" %>
<%
}
}
%>
</body>
</html>