我正在 gae 上的 struts2 中尝试一个简单的应用程序,但在提交表单时遇到问题。
struts.xml 配置文件
<package name="auth" extends="struts-default" namespace="/auth">
<default-interceptor-ref name="defaultStack"/>
<action name="signup" class="signup" method="signup">
<result name="success">/auth/signup.jsp</result>
</action>
<action name="postSignup" class="signup" method="create">
<result name="input">/auth/signup.jsp</result>
</action>
<action name="signupConfirm" class="signup" method="signupConfirm"></action>
<action name="resendCode" class="signup" method="resendCode"/>
</package>
我正在使用弹簧来加载动作。
当我点击 url /auth/signup.html 时,我得到了正确的注册页面。现在提交表单后,如果表单验证失败(我正在通过我的操作中的 validate 方法执行此操作)。它让我回到同一个jsp。现在的主要问题是:即使我在验证方法中添加了 fielderror 并且我在表单中使用了 struts 标签,我也看不到错误。
@Override
public void validate() {
if(!StringUtil.isValidUserName(userForm.getUserName())){
addFieldError("userForm.userName", "Invalid username format");
}else {
TutorUser user = this.userBc.getUserByUserName(userForm.getUserName());
if(user!=null){
addFieldError("userForm.userName", "Username already exist. Please choose a different one.");
}
}
if(!StringUtil.isEmail(userForm.getEmail())){
addFieldError("userForm.email", "Invalid email provided");
}
if(StringUtil.isBlank(userForm.getPassword1()) || StringUtil.isBlank(userForm.getPassword2()) ||
!userForm.getPassword1().equals(userForm.getPassword2())) {
addFieldError("userForm.password2", "Passwords do not match");
}
}
如果我再次点击 /auth/signup.html ,也从这个页面开始,它会给出这个错误 -
Problem accessing /auth/signup.html. Reason:
No result defined for action com.tutorial.action.auth.SignUpAction and result input
对于“注册”操作,我不需要在我的 conf 中进行“输入”,因为我只会显示注册表单。此外,除了“postSignup”方法之外,我@SkipValidation
还在每个方法上添加了注释。我是struts2的新手。从 struts1 迁移。需要帮助。另外,我如何更好地组织我的 struts 配置?谢谢
这是jsp
<s:form action="postSignup" cssClass="well" namespace="/auth" method="POST">
<fieldset>
<div class="control-group">
<label class="control-label" for="userName">UserName</label>
<div class="controls">
<s:textfield cssClass="input-large" id="userName" name="userForm.userName"/>
<span class="help-inline">Choose a username</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="password1">Password</label>
<div class="controls">
<s:password cssClass="input-large" id="password1" name="userForm.password1"/>
<span class="help-inline">Enter your Password</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="password2">Confirm Password</label>
<div class="controls">
<s:password cssClass="input-large" name="userForm.password2" id="password2"/>
<span class="help-inline">Confirm above password</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">Email Address</label>
<div class="controls">
<s:textfield cssClass="input-large" id="email" name="userForm.email"/>
<span class="help-inline">Enter your Email Address</span>
</div>
</div>
<div class="form-actions">
<s:submit name="action" id="action" value="SignUp" cssClass="btn btn-primary"/>
</div>
</fieldset>
</s:form>