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

Arqui 2004-09-22 11:50:44
功能:输入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
* found, return an <code>ActionErrors</code> object containing the errors.
* If no validation errors occur, return <code>null</code> or an empty
* <code>ActionErrors</code> object.
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {

ActionErrors errors = new ActionErrors();

if ((userName == null) || (userName.length() < 1))
errors.add("username", new ActionMessage("hello.no.username.error"));

return errors;
}
}

现在的情况是错误输入时:提示

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException

大家救命啊,这个是什么毛病呢??
...全文
166 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xunyiren 2004-09-22
  • 打赏
  • 举报
回复
sorry,看这个

struts-config.xml==><action-mappings>标记中对应path="/HelloWorld"的<action/>标记里,配属性
validate="true" input="/yourinput.jsp"
xunyiren 2004-09-22
  • 打赏
  • 举报
回复
struts-config.xml==><action-mappings>标记中对应path="/HelloWorld"的<action/>标记里,配属性
validat="true" input="/yourinput.jsp"
discolt 2004-09-22
  • 打赏
  • 举报
回复
org.apache.jasper.JasperException 编译错误
treeroot 2004-09-22
  • 打赏
  • 举报
回复
估计是编译错误
lovehuangyuan 2004-09-22
  • 打赏
  • 举报
回复
关注
Arqui 2004-09-22
  • 打赏
  • 举报
回复
顶上去!!!求更多建议
Arqui 2004-09-22
  • 打赏
  • 举报
回复
ok ! let me hv a try.
shangqiao 2004-09-22
  • 打赏
  • 举报
回复
你在你的ActionForm加上几条语句,看看到底你的userName等于什么,可以将form的method设为get以方便调试
Arqui 2004-09-22
  • 打赏
  • 举报
回复
按要求设置完还是不能返回,xunyiren!!帮帮我!加我MSN:arqui2004@hotmail.com希望和你成为朋友
Arqui 2004-09-22
  • 打赏
  • 举报
回复
我的struts-config是这个样子的:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<!--
This is the Struts configuration file for the "Hello!" sample application
-->

<struts-config>

<!-- ======== Form Bean Definitions =================================== -->
<form-beans>
<form-bean name="HelloForm" type="hello.HelloForm"/>
</form-beans>

<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
<!-- Say Hello! -->
<action path = "/HelloWorld"
type = "hello.HelloAction"
name = "HelloForm"
scope = "request"
validate = "true"
input = "/hello.jsp"
>
<forward name="SayHello" path="/hello.jsp" />
</action>
</action-mappings>

<!-- ========== Message Resources Definitions =========================== -->
<message-resources parameter="com.youcompany.struts.ApplicationResources" />
</struts-config>

67,513

社区成员

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

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