首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

STRUTS问题- form bean的validate方法为什么没能给我返回error?

2014-01-26 
功能:输入USERNAM将会有欢迎字样;输入错误(NULL)将会有ERROR提示;输入正确时限是正确error显示页:%@ page

功能:输入USERNAM将会有欢迎字样;
  输入错误(NULL)将会有ERROR提示;
  输入正确时限是正确
 
  error显示页:
  <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
  <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
 
  <html:html locale="true">
  <head>
  <title><bean:message key="hello.jsp.title"/></title>
  <html:base/>
  </head>
 
  <body bgcolor="white"><p>
  <h2><bean:message key="hello.jsp.page.heading"/></h2><p>
  <html:errors /><p>
 
  <logic:present name="personbean" scope="request">
  <h2>
  <bean:message key="hello.jsp.page.hello"/>
  <bean:write name="personbean" property="userName" />!<p>
  </h2>
  </logic:present>
 
  <html:form action="/HelloWorld.do" focus="userName" >
  <bean:message key="hello.jsp.prompt.person"/>
  <html:text property="userName" size="16" maxlength="16"/><br>
  <html:submit property="submit" value="Submit"/>
  <html:reset/>
 
  </html:form><br>
 
  <html:img page="/img/cat.jpg" alt="Powered by Cat"/>
  </body>
  </html:html>
 
  formbean:
  package hello;
 
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionMessage;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionMapping;
 
  public final class HelloForm extends ActionForm {
 
  private String userName = null;
 
  public String getUserName() {
  return (this.userName);
  }
 
  public void setUserName(String userName) {
  this.userName = userName;
  }
 
  /**
  * Reset all properties to their default values.
  */
  public void reset(ActionMapping mapping, HttpServletRequest request) {
  this.userName = null;
  }
 
  /**
  * Validate the properties posted in this request. If validation errors are         

热点排行