我把代码都帖出来吧.不多.
JSP页面代码:
<%@ page contentType="text/html; charset=GB2312" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JSP for zzForm form</title>
</head>
<body>
<html:form action="/zz" onsubmit="return validatezzForm(this);">
zz : <html:text property="zz"/><html:errors property="zz"/><br/>
<html:submit/><html:cancel/>
</html:form>
<html:javascript formName="zzForm"/>
</body>
</html>
Action form是动态的,在struts-config.xml中定义的.
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>
<data-sources />
<form-beans >
<form-bean name="zzForm" type="org.apache.struts.validator.DynaValidatorActionForm">
<form-property name="zz" type="java.lang.String" />
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
input="/zz.jsp"
name="zzForm"
path="/zz"
scope="request"
type="com.yourcompany.struts.action.zzAction" />
</action-mappings>
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>
validation.xml代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
<form-validation>
<formset>
<form name="zzForm">
<field property="zz"
depends="required">
<arg0 key="prompt.accountID"/>
</field>
</form>
</formset>
</form-validation>
资源文件也定义了.
Action不关事吧,相应的zzAction我是myeclipse生成的,什么都没改.
大家帮我看看吧,我为了它头都想大了,实在找不到错在哪里,网上查了好多,都是这样做的啊.
异常如下:
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NullPointerException
org.apache.struts.taglib.html.JavascriptValidatorTag.doStartTag(JavascriptValidatorTag.java:316)
org.apache.jsp.zz_jsp._jspx_meth_html_javascript_0(zz_jsp.java:216)
org.apache.jsp.zz_jsp._jspService(zz_jsp.java:90)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
还有,我一去桌zz.jsp页面中的<html:javascript formName="zzForm"/>就没错了...
我把文件一起上传来哈.