专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Java Exception

在struts中使用 <html:errors/>不会显示错误请问是错在哪里?

发布时间:2010-06-05 12:33:41 文章来源:www.iduyao.cn 采编人员:星星草

在struts中使用 <html:errors/>不会显示错误请问是错在哪里?
  我要使输入框不能为空 不然显示 "不能为空!" 但是实际运行是我不输入内容点提交,页面刷新了一下就是没有显示文字.
  jsp代码:
  <%@ page contentType="text/html; charset=UTF-8" language="java" %>
  <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  <html>
  <head>
  <title>
  jsp1
  </title>
  </head>
  <body bgcolor="#ffffff">
  <html:errors/>
  <html:form action="/tAction.do" focus="username">
  <html:text property="username" /><br>
  <html:submit property="submit" value="Submit">
  </html:submit>
  </html:form>
  </body>
  </html>
 
  tActionForm的validate方法代码是
  public ActionErrors validate(ActionMapping mapping,
      HttpServletRequest request) {
  ActionErrors errors=new ActionErrors();
  if((username==null)||(username.length()<1)){
  errors.add("ee",new ActionError("不能为空!"));
  return errors;
  }else{
  return null;
  }
 
  }
  Struts_config.xml代码:
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
  <struts-config>
  <form-beans>
  <form-bean name="tActionForm" type="errortest.tActionForm"/>
  </form-beans>
  <action-mappings>
  <action input="/jsp1.jsp" name="tActionForm" path="/tAction" scope="request" type="errortest.tAction" validate="true">
  <forward name="succe" path="/jsp2.jsp"/>
  </action>
  </action-mappings>
  </struts-config>

------解决方法--------------------------------------------------------
<html:errors/> 应该放到form里
  其实这种非空校验可以用javascript,节约服务器的资源
------解决方法--------------------------------------------------------
同意,用javascript验证这种东西较好,避免提交一次,浪费资源
------解决方法--------------------------------------------------------
new ActionError("不能为空!"));
 
  应为 new ActionError("errors.abc"));
 
  在 ApplicationResources.properties中     

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: