struts标签的用法

passwords 2005-09-27 01:21:44
----------------------------------jsp-------------------------------------
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<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="/helloAction.do" focus="userName">
<bean:message key="hello.jsp.prompt.person"/>
<html:text property="userName" size="6" maxlength="16"/><br>
<html:submit property="submit" value="submit"/>
<html:reset/>
</html:form><br>
</body>
</html:html>



---------------------------------------------actionForm------------------------------
package hello;

import org.apache.struts.action.*;
import javax.servlet.http.*;
public class HelloForm extends ActionForm {
private String userName=null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
/**@todo: finish this method, this is just the skeleton.*/
ActionErrors errors=new ActionErrors();
if((userName==null||(userName.length()<1)))
errors.add("username",new ActionMessage("hello.no.username.error"));
return errors;
}
public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
userName = null;
}
}



进行actionform验证时返回jsp时到<html:errors/>标签时报
java.lang.ClassCastException
at org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
怎么解决!!
...全文
140 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjj317 2005-09-27
  • 打赏
  • 举报
回复
注意struts1.0与struts1.1,两者的差别。
passwords 2005-09-27
  • 打赏
  • 举报
回复
恩!改成new ActionError就好了,再问下在Action 这个基类里有saveError()这个方法吗?书上说有我在action中用的时候怎么说找不到
xiaozhen 2005-09-27
  • 打赏
  • 举报
回复
新版本的struts好像用的是ActionError对象了,比如
errors.add("username",new ActionError("hello.no.username.error"));

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧