求助,我使用struts,为什么不能进行输入验证呀?

xhair
03-01-04 8 278

只要允许输入验证,程序就会出错。不知是我那里写错了。。
程序我是用jbuilder8写的,里面对struts的支持挺不错。


出错代码如下:

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.IllegalArgumentException: Path reguser.asp does not start with a "/" character
at org.apache.catalina.core.ApplicationContext.getRequestDispatcher(ApplicationContext.java:572)
at org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:174)
at org.apache.struts.action.ActionServlet.processValidate(ActionServlet.java:2142)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1565)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)



以下是我的源代码

reguser.jsp
----------------------------------------------------

<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri=
"/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri=
"/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri=
"/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri=
"/WEB-INF/struts-html.tld" prefix="html" %>
<html:html xhtml=
"true" locale="true">
<head>
<title>
reguser
</title>
</head>
<body>
<h1>JBuilder Generated Struts JSP for ActionForm studystructs.RegUserForm</h1>
<font color=
"red"><html:errors/></font>
<p>
<html:form action=
"/regUserAction" method="POST">
email <html:text property=
"email" size="20" maxlength="30"/>
<br>
logname <html:text property=
"logname" size="10" maxlength="10"/>
<br>
password <html:text property=
"password" size="10" maxlength="20"/>
<br>
<html:submit property=
"submit" value="Submit"/><br>
<html:reset value =
"Reset"/>
</html:form>
</body>
</html:html>



RegUserForm.java
-------------------------------------------------------


package studystructs;

import org.apache.struts.action.*;
import javax.servlet.http.*;

public class RegUserForm extends ActionForm {
private String email;
private String logname;
private String password;
private String welstr;

public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public void setLogname(String logname) {
this.logname = logname;
}
public String getLogname() {
return logname;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}

public void initWelStr(){
welstr = "Welcome!!" + logname +".<br> 欢迎您来到Struts的世界!";

}
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
/**@todo: finish this method, this is just the skeleton.*/
ActionErrors errors = new ActionErrors();
if ((logname == null) || (logname.length() < 1))
errors.add(
"username", new ActionError("error.username.required"));
if ((password == null) || (password.length() < 5))
errors.add(
"password", new ActionError("error.password.required"));

return errors;
}

public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
logname = null;
password = null;
email = null;
}
}


RegUserAction.java
------------------------------------------------------


package studystructs;

import org.apache.struts.action.*;
import javax.servlet.http.*;

public class RegUserAction extends Action {
public ActionForward perform(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/

((RegUserForm)actionForm).initWelStr();

return (actionMapping.findForward(
"success"));
//throw new java.lang.UnsupportedOperationException("Method perform() not yet implemented.");
}
}



struts-config.xml
-----------------------------------------------------------------


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<form-beans>
<form-bean name=
"regUserForm" type="studystructs.RegUserForm" />
</form-beans>
<action-mappings>
<action name=
"regUserForm" type="studystructs.RegUserAction" validate="true" input="reguser.asp" scope="request" path="/regUserAction">
<forward name=
"success" path="/messageSuccess.jsp" />
</action>
</action-mappings>
</struts-config>

hymmyh
2003-01-06 11:23

> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE struts-config PUBLIC "-//Apache Software
> Foundation//DTD Struts Configuration 1.0//EN"
> "http://jakarta.apache.org/struts/dtds/struts-config_1
> 0.dtd">
> <struts-config>
> <form-beans>
> <form-bean name="regUserForm"
> rm" type="studystructs.RegUserForm" />
> </form-beans>
> <action-mappings>
> <action name="/regUserForm"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> rm" type="studystructs.RegUserAction" validate="true"
> input="reguser.asp" scope="request"
> path="/regUserAction">
> <forward name="success"
> cess" path="/messageSuccess.jsp" />
> </action>
> </action-mappings>
> </struts-config>
> [/code]

你的xml配置错误

hymmyh
2003-01-06 11:25

action name="/regUserForm" type="studystructs.RegUserAction"
~ ~~~~~~~~~~~~
你的xml配置错误

xhair
2003-01-06 13:49

to hymmyh
那应该怎么样配置呀??我是用jbuilder8里面,直接填写的!!

为什么这样配置就验证不了呢??

hymmyh
2003-01-06 22:12

你那个少了/
你看我上面打了~~~的地方。

2Go 1 2 下一页