我是ATG的新手。我正在尝试使用自己的RepositoryFormHandler。但我无法在表格上进行验证。
这是我的.java文件:
public class MyLoginBean extends RepositoryFormHandler {
private String logname;
private String logpwd;
private String message;
public String getLogname() {
return logname;
}
public void setLogname(String logname) {
this.logname = logname;
}
public String getLogpwd() {
return logpwd;
}
public void setLogpwd(String logpwd) {
this.logpwd = logpwd;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public boolean handleLogname(DynamoHttpServletRequest pRequest,
DynamoHttpServletResponse pResponse) throws ServletException,
IOException {
boolean tf=true;
if(logname.isEmpty() || logname==null)
{
tf=false;
setMessage("User name can't empty");
}
System.out.println("inside logname");
return tf;
}
public void handleFormException(DropletFormException exception,
DynamoHttpServletRequest request, DynamoHttpServletResponse response) {
// TODO Auto-generated method stub
super.handleFormException(exception, request, response);
}
}
这是我的.jsp文件:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/dspTaglib" prefix="dsp" %>
<dsp:importbean bean="/atg/dynamo/droplet/ErrorMessageForEach"/>
<dsp:importbean bean="/dynamusic/MyLoginBean"/>
<!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>Custom Login</title>
</head>
<body>
<dsp:form style="color:white">
<table style="background:#3b5998">
<tr>
<td>
<ul>
<dsp:droplet name="ErrorMessageForEach">
<dsp:param bean="MyLoginBean.formExceptions" name="exceptions"/>
<dsp:oparam name="output">
<li>
<dsp:valueof param="message"/>
</li>
</dsp:oparam>
</dsp:droplet>
</ul>
</td>
</tr>
<tr>
<td>
User Name:
</td>
<td>
Password:
</td>
</tr>
<tr>
<td>
<dsp:input type="text" name="logname" bean="MyLoginBean.logname"> </dsp:input>
</td>
<td>
<dsp:input type="password" name="logpwd" bean="MyLoginBean.logpwd"> </dsp:input>
</td>
<td>
<dsp:input type="submit" bean="MyLoginBean.login"> </dsp:input>
</td>
</tr>
</table>
</dsp:form>
</body>
</html>
这是我到目前为止所做的一切,还在尝试别的东西。 请为此建议解决方案,并告诉我在此处粘贴的代码中的错误(如果有)。
答案 0 :(得分:7)
addFormException(new DropletException("Your error message"));
然后,在方法结束时,请致电:
return checkFormRedirect(getSuccessUrl(), getFailUrl(), pRequest, pResponse);
检查是否添加了任何表单异常,如果是,则重定向到failUrl,否则重定向到successUrl。