これはおそらくどこかの非常に単純なエラーです。助けてください。<form:form>
次の 2 つのタグを持つ home.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">
<%@ taglib uri="/META-INF/c.tld" prefix="c"%>
<%@ taglib uri="/META-INF/fmt.tld" prefix="fmt"%>
<%@ taglib uri="/META-INF/spring-form.tld" prefix="form"%>
<html>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<head>
<title>Home Page</title>
</head>
<body>
<div>
<form:form name="loginForm" modelAttribute="loginUser" action="login" method="post">
<c:if test="${loginMsg != null}"><c:out value="${loginMsg}"></c:out></c:if>
<br/>
Email: <form:input name="loginEmail" id="loginEmail" value="" path="email"/>
<form:errors path="email" cssClass="error" />
<br/>
password: <form:password name="loginPassword" Id="loginPassword" value="" path="password" />
<form:errors path="password" />
<br/>
<input type="submit" id="id_login" value="Login">
</form:form>
</div>
<div>
<form:form name="SignUpForm" modelAttribute="signUpUser" action="signup" method="post">
<c:if test="${signupMsg != null}"><c:out value="${signupMsg}"></c:out></c:if>
<br/>
Full Name: <form:input name="name" id="name" value="" path="name"/>
<form:errors path="name" cssClass="error" />
<br/>
Email: <form:input name="signupEmail" id="signupEmail" value="" path="email"/>
<form:errors path="email" cssClass="error" />
<br/>
password: <form:password name="signUpPassword" Id="signUpPassword" value="" path="password" />
<form:errors path="password" />
<br/>
<input type="submit" id="id_signUp" value="Sign Up">
</form:form>
</div>
</body>
</html>
各フォームは、異なるコントローラーによって処理されます。問題は、フォームの 1 つ (だけ) に入力して送信ボタンをクリックすると、両方のModelAttribute
s に同じ値が入力されることです。
私のコントローラーには特別なことは何もありません:
@RequestMapping("/login")
public String login(@ModelAttribute("loginUser") User user,
BindingResult result, @ModelAttribute("signUpUser") User signUpUser,
BindingResult signUpResult, ModelMap model, HttpServletRequest request,
HttpServletResponse response) {
// Here, both user and signUpUser have the same value (WHY?)
// But I dint fill the sign up form at all
loginFormValidator.validate(user, result);
if(Errors in `result`)
return "forward:/home";
// Authentication Logic
request.getSession().setAttribute("s_user_obj", some_variable);
return "forward:/home";
}
アップデート:
生成された HTML は次のとおりです。アクションの前にlogin
:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<head>
<title>Welcome to m0m0</title>
</head>
<body>
<div>
<form id="loginUser" name="loginForm" action="login" method="post">
<br/>
Email: <input id="loginEmail" name="email" name="loginEmail" type="text" value=""/>
<br/>
password: <input id="password" name="password" name="loginPassword" Id="loginPassword" type="password" value=""/>
<br/>
<input type="submit" id="id_login" value="Login">
</form>
</div>
<div>
<form id="signUpUser" name="SignUpForm" action="signup" method="post">
<br/>
Full Name: <input id="name" name="name" name="name" type="text" value=""/>
<br/>
Email: <input id="signupEmail" name="email" name="signupEmail" type="text" value=""/>
<br/>
password: <input id="password" name="password" name="signUpPassword" Id="signUpPassword" type="password" value=""/>
<br/>
<input type="submit" id="id_signUp" value="Sign Up">
</form>
</div>
</body>
</html>
アクションの後login
:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<head>
<title>Welcome to m0m0</title>
</head>
<body>
<div>
<form id="loginUser" name="loginForm" action="login" method="post">
<br/>
Email: <input id="loginEmail" name="email" name="loginEmail" type="text" value="a@b.com"/>
<br/>
password: <input id="password" name="password" name="loginPassword" Id="loginPassword" type="password" value=""/>
<br/>
<input type="submit" id="id_login" value="Login">
</form>
</div>
<div>
<form id="signUpUser" name="SignUpForm" action="signup" method="post">
<br/>
Full Name: <input id="name" name="name" name="name" type="text" value=""/>
<br/>
Email: <input id="signupEmail" name="email" name="signupEmail" type="text" value="a@b.com"/>
<br/>
password: <input id="password" name="password" name="signUpPassword" Id="signUpPassword" type="password" value=""/>
<br/>
<input type="submit" id="id_signUp" value="Sign Up">
</form>
</div>
</body>
</html>