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

页面用<html:errors/>有什么限制?为什么我的会出错?

2014-01-26 
页面%@ page contentTypetext/html charsetGBK languagejava %%@ taglib uri/WEB-INF/struts-

页面
  <%@ page contentType="text/html; charset=GBK" 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" %>
  <%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
 
 
  <html>
  <head>
  <title>
  登录
  </title>
  </head>
  <body bgcolor="#ffffff">
  <html:errors property="org.apache.struts.action.GLOBAL_MESSAGE"/>
  <html:form action="/adminLogin.do" focus="userName">
  <html:text property="userName" size="16" maxlength="16"/>
  <bean:message key="form.userName.length" />
  <br>
  <html:submit property="submit" value="Submit"/>
  </html:form>
  </body>
  </html>
 
 
  =====================
  在FormBean里
  package Bean;
 
  import org.apache.struts.action.*;
  import javax.servlet.http.*;
 
  public class AdminLoginForm extends ActionForm {
  private String userName;
  public void setUserName(String userName) {
  this.userName = userName;
  }
  public String getUserName() {
  return userName;
  }
  public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
  ActionErrors errors = new ActionErrors();
  try{
  if ( (userName == null) || (userName.length() < 1))
  errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("form.userName.length"));
  }
  catch(Exception e){
  System.out.println("======here");
  }
  return errors;
  }
 
  public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
  this.userName=null;
  }
  }
 
  为什么我在文本框不输入任何东西就提交,就会出现这种错误提示
  --------------------------------------------------------------------------------
 
  type Exception report
 
  message Internal Server Error
 
  description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
 
  exception
 
  java.lang.ClassCastException
  at org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
  at org.apache.jsp.Admin_0005flogin$jsp._jspService(Admin_0005flogin$jsp.java:80)
  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683)         

热点排行