package org.apache.struts.webapp.example;import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;public final class LogonForm extends ActionForm { private String password = null;
private String username = null; public String getPassword() {
return (this.password);
} public void setPassword(String password) {
this.password = password;
} public String getUsername() {
return (this.username);
} public void setUsername(String username) {
this.username = username;
} public void reset(ActionMapping mapping, HttpServletRequest request) {
this.password = null;
this.username = null;
}
/**
* Validate the properties that have been set from this HTTP request,
* and return an <code>ActionErrors</code> object that encapsulates any
* validation errors that have been found. If no errors are found, return
* <code>null</code> or an <code>ActionErrors</code> object with no
* recorded error messages.
*
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if ((username == null) || (username.length() < 1))
errors.add("username", new ActionError("error.username.required"));
if ((password == null) || (password.length() < 1))
errors.add("password", new ActionError("error.password.required"));
return errors;
}
}
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;public final class LogonForm extends ActionForm { private String password = null;
private String username = null; public String getPassword() {
return (this.password);
} public void setPassword(String password) {
this.password = password;
} public String getUsername() {
return (this.username);
} public void setUsername(String username) {
this.username = username;
} public void reset(ActionMapping mapping, HttpServletRequest request) {
this.password = null;
this.username = null;
}
/**
* Validate the properties that have been set from this HTTP request,
* and return an <code>ActionErrors</code> object that encapsulates any
* validation errors that have been found. If no errors are found, return
* <code>null</code> or an <code>ActionErrors</code> object with no
* recorded error messages.
*
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if ((username == null) || (username.length() < 1))
errors.add("username", new ActionError("error.username.required"));
if ((password == null) || (password.length() < 1))
errors.add("password", new ActionError("error.password.required"));
return errors;
}
}
HttpServletRequest request)或public void reset(ActionMapping mapping, HttpServletRequest request)就可以了,struts什么时候调用呢》
http://www.chinajavaworld.net/non-cgi/usr/48/48_46.doc
都在这里了
http://www.chinajavaworld.net/forum/jinghua.cgi?action=list&forum=48
确实每个页面都做一个formbean让人感觉受不了
struts1.1可以不用为每个表单都做一个forumbean了,可以在struts-config.xml里设置。
to ccjsmile() :
怎么配置??给出格式吧