2008-10-13 16:01:25 org.apache.commons.digester.Digester error
严重: Parse Error at line 45 column 15: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
org.xml.sax.SAXParseException: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:172)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:2048)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:932)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanEndElement(XMLNSDocumentScannerImpl.java:719)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
at org.apache.commons.digester.Digester.parse(Digester.java:1581)
at org.apache.commons.validator.ValidatorResources.<init>(ValidatorResources.java:153)
at org.apache.struts.validator.ValidatorPlugIn.initResources(ValidatorPlugIn.java:233)
at org.apache.struts.validator.ValidatorPlugIn.init(ValidatorPlugIn.java:164)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:839)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:332)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3956)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4230)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:831)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:720)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1150)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
25 个解决方案
#1
严重: Parse Error at line 45 column 15: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
45行15列的“formset”元素不完全全
45行15列的“formset”元素不完全全
#2
的确是validation.xml文件的问题。
<formset>中至少得有一个<form>元素,你仔细检查一下,是否写错了?
<formset>中至少得有一个<form>元素,你仔细检查一下,是否写错了?
#3
validation.xml是myeclipse自动生成的呀...
#4
你是不是动里面的东西了?
#5
我知道了,你可能压根儿就没往这里边写东西,甚至压根儿就没打开看过,是吗?
你得往里边写验证规则呀,呵呵。
#6
强悍!你说对了,我不知道还要往里边写东西的呢,不过..我的myeclipse里只有validator-rules.xml啊,找不着validation.xml~~,是不是要自己建一个的啊?
#7
是的 不然没法调用ActionForm 中的Validate方法
如果你想做验证的话,建议还是用 JavaScript吧
不然配置 Validation.xml 很繁琐的
如果你想做验证的话,建议还是用 JavaScript吧
不然配置 Validation.xml 很繁琐的
#8
书上说validation_1_1.dtd描述了validation.xml....可是我validation到处都找不到,我想就自己建一个吧,可那个用来约束的dtd怎么写?myeclipse里自动生成的valitior-rules.xml的前两句是<!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">
而我旧书上说是validator-rules_1_1.dtd定义validatior-rules.xml的...是不是把"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd"改成"http://jakarta.apache.org/commons/dtds/validator_1_1.dtd"就行了?
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
而我旧书上说是validator-rules_1_1.dtd定义validatior-rules.xml的...是不是把"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd"改成"http://jakarta.apache.org/commons/dtds/validator_1_1.dtd"就行了?
#9
改了还不行呀~~怎么还是报这个错??信息: Loading validation rules file from '/WEB-INF/validation.xml'
2008-10-15 0:11:30 org.apache.commons.digester.Digester error
严重: Parse Error at line 45 column 15: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
org.xml.sax.SAXParseException: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
连行列都一样的!可是我的validation.xml'总共都没有45行呢!!怎么回事?
2008-10-15 0:11:30 org.apache.commons.digester.Digester error
严重: Parse Error at line 45 column 15: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
org.xml.sax.SAXParseException: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
连行列都一样的!可是我的validation.xml'总共都没有45行呢!!怎么回事?
#10
2008-10-15 0:21:42 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: G:\eclipse\jdk1.5.0_06\bin;C:\Tomcat 5.5\bin
2008-10-15 0:21:42 org.apache.coyote.http11.Http11BaseProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2008-10-15 0:21:42 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1156 ms
2008-10-15 0:21:43 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2008-10-15 0:21:43 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/5.5.27
2008-10-15 0:21:43 org.apache.catalina.core.StandardHost start
信息: XML validation disabled
2008-10-15 0:21:44 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-blank.war
2008-10-15 0:21:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module ''.
2008-10-15 0:21:44 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 0:21:44 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validation.xml'
2008-10-15 0:21:45 org.apache.commons.digester.Digester error
严重: Parse Error at line 45 column 15: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
org.xml.sax.SAXParseException: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
它凭什么总是报这个错??!!还总是line 45 column 15的!可是validation.xml是这样的:<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validation_1_1.dtd">
<form-validation>
<formset>
<form name="HelloForm">
<field property="userName" depends="my">
<msg name="userName" key="hello.no.username.error" resource="true"/>
</field>
</form>
</formset>
</form-validation>
我怀疑它加载的根本就不是我自己写的这个validation.xml啊!怎么回事~~?前辈们???help~~
信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: G:\eclipse\jdk1.5.0_06\bin;C:\Tomcat 5.5\bin
2008-10-15 0:21:42 org.apache.coyote.http11.Http11BaseProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2008-10-15 0:21:42 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1156 ms
2008-10-15 0:21:43 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2008-10-15 0:21:43 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/5.5.27
2008-10-15 0:21:43 org.apache.catalina.core.StandardHost start
信息: XML validation disabled
2008-10-15 0:21:44 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-blank.war
2008-10-15 0:21:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module ''.
2008-10-15 0:21:44 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 0:21:44 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validation.xml'
2008-10-15 0:21:45 org.apache.commons.digester.Digester error
严重: Parse Error at line 45 column 15: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
org.xml.sax.SAXParseException: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
它凭什么总是报这个错??!!还总是line 45 column 15的!可是validation.xml是这样的:<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validation_1_1.dtd">
<form-validation>
<formset>
<form name="HelloForm">
<field property="userName" depends="my">
<msg name="userName" key="hello.no.username.error" resource="true"/>
</field>
</form>
</formset>
</form-validation>
我怀疑它加载的根本就不是我自己写的这个validation.xml啊!怎么回事~~?前辈们???help~~
#11
在MyEclipse中,validation.xml得自己创建,其DTD与validator-rules.xml完全相同,复制过来即可,千万不要去改。
把你写的validation.xml的内容贴出来,然后发则消息给我,给你看看。
你的ActionForm继承的是哪个类?把它的源码全贴出来。
把struts-config.xml中的<plug-in>也贴出来,都检查一下。
把你写的validation.xml的内容贴出来,然后发则消息给我,给你看看。
你的ActionForm继承的是哪个类?把它的源码全贴出来。
把struts-config.xml中的<plug-in>也贴出来,都检查一下。
#12
哦,我看到你贴出来的validation.xml了。
我料你还不会写自定义验证器,那depends="my"肯定有问题。
你想做非空验证的话,应该写成:
depends="required"
但是现在这不是关键问题。
你把那个改过的DTD先删了,从validator-rules.xml中再次复制它的DTD过来,粘validation.xml上头,不要改版本了,再试试。
你是用MyEclipse吧?
如果你想用validator1.1,你就换成Struts1.2试试。
我料你还不会写自定义验证器,那depends="my"肯定有问题。
你想做非空验证的话,应该写成:
depends="required"
但是现在这不是关键问题。
你把那个改过的DTD先删了,从validator-rules.xml中再次复制它的DTD过来,粘validation.xml上头,不要改版本了,再试试。
你是用MyEclipse吧?
如果你想用validator1.1,你就换成Struts1.2试试。
#13
=================我的ActionForm==============
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
#14
=================我的ActionForm==============
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
#15
=================我的ActionForm==============
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
#16
嗯……ActionForm没问题,插件的配置没问题。
你还自己写了个验证器(恰好超出我的意料),真强!
从你发上来的代码,没看出什么问题。
你不一定要用Struts1.2,这一点我之前说的很明白:
如果你想用validator1.1,你就换成Struts1.2试试。
之所以提这个建议,是因为你书上的代码用的是validator1.1,而MyEclipse中Struts1.1中的validator的版本为1.0,跟你书上的代码的版本不一样。而validator框架,1.0和1.1是有很大区别的,他们的DTD、配置文件不可以混用,自定义验证器的写法也不一样。
当然使用Struts1.1是可以做出来的,但是你现在还只会照着书做,所以我才建议你用Struts1.2,是因为它带的validator是1.1的版本,用起来,跟书上的代码贴近些。换句话说,你成功的可能性更高一些。
看你很不情愿,那就算啦。算我多事。呵呵。
你还自己写了个验证器(恰好超出我的意料),真强!
从你发上来的代码,没看出什么问题。
你不一定要用Struts1.2,这一点我之前说的很明白:
如果你想用validator1.1,你就换成Struts1.2试试。
之所以提这个建议,是因为你书上的代码用的是validator1.1,而MyEclipse中Struts1.1中的validator的版本为1.0,跟你书上的代码的版本不一样。而validator框架,1.0和1.1是有很大区别的,他们的DTD、配置文件不可以混用,自定义验证器的写法也不一样。
当然使用Struts1.1是可以做出来的,但是你现在还只会照着书做,所以我才建议你用Struts1.2,是因为它带的validator是1.1的版本,用起来,跟书上的代码贴近些。换句话说,你成功的可能性更高一些。
看你很不情愿,那就算啦。算我多事。呵呵。
#17
15楼说的不错!~!
也算我多事哈!~!你应该采取他的建议!~!
对你很有好处的!~!呵呵
也算我多事哈!~!你应该采取他的建议!~!
对你很有好处的!~!呵呵
#18
疯了疯了,快疯了!!啊~~我用了1.2的可是还不行 就连出错的位置都是Error at line 45 column 15!每次都是这样,
===================================下面是我的验证处理类===========有错吗?====================
package com.yourcompany.struts;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.Field;
import org.apache.commons.validator.util.ValidatorUtils;
import org.apache.commons.validator.ValidatorAction;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionMessage;
public class Check implements Serializable {
public static boolean validateMonster(Object bean,
ValidatorAction va,Field field,
ActionMessages errors,
HttpServletRequest request){
String userName = ValidatorUtils.getValueAsString(bean, field.getProperty());
if(userName==null||userName.length()<1)
errors.add("username", new ActionMessage("hello.no.username.error"));
return (errors.isEmpty());
}
}
===================================下面是我的验证处理类===========有错吗?====================
package com.yourcompany.struts;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.Field;
import org.apache.commons.validator.util.ValidatorUtils;
import org.apache.commons.validator.ValidatorAction;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionMessage;
public class Check implements Serializable {
public static boolean validateMonster(Object bean,
ValidatorAction va,Field field,
ActionMessages errors,
HttpServletRequest request){
String userName = ValidatorUtils.getValueAsString(bean, field.getProperty());
if(userName==null||userName.length()<1)
errors.add("username", new ActionMessage("hello.no.username.error"));
return (errors.isEmpty());
}
}
#19
顺便问一下...对表单字段的验证 我是不是可以直接放在ActionForm里的validate()方法里啊?我干脆不用validator框架就行啦~
可是我每次add struts capabilities时 就自动生成了validator-rules.xml了 而且就算我不去配置它也不新建vaildation.xml,当启动tomcat时 也会自动加载vaildation.xml和validator-rules.xml的..所以我想啊 它每次都是line 45 column 15这里出错了 会不会是因为它压根就没当我写的vaildation.xml的存在?然后加载一个默认的vaildation.xml?可是我找不到哪里还有vaildation.xml...扯远了,回到原来话题..我如果不用validator框架行不行的啊?怎么做才不会自动生成validator-rules.xml呢?我试过把它生成的validator-rules.xml删了然后启动tomcat的 可是它还会再次生成那讨厌的validator-rules.xml!!!
可是我每次add struts capabilities时 就自动生成了validator-rules.xml了 而且就算我不去配置它也不新建vaildation.xml,当启动tomcat时 也会自动加载vaildation.xml和validator-rules.xml的..所以我想啊 它每次都是line 45 column 15这里出错了 会不会是因为它压根就没当我写的vaildation.xml的存在?然后加载一个默认的vaildation.xml?可是我找不到哪里还有vaildation.xml...扯远了,回到原来话题..我如果不用validator框架行不行的啊?怎么做才不会自动生成validator-rules.xml呢?我试过把它生成的validator-rules.xml删了然后启动tomcat的 可是它还会再次生成那讨厌的validator-rules.xml!!!
#20
错。如果你不配置这个
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
那么validator-rules.xml是不会被用到的(自然也就不会出问题了)。换句话说,如果你不打算使用验证器框架,你可以对它视而不见。
看样子,也只好这样了……就用validate()方法完成验证吧,呵呵。
#21
不行啊!去掉了<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
也不行!而且我发现啊
--------------------------------------------------------------------------------------------------------
信息: Deploying web application archive struts-documentation.war
2008-10-15 23:23:08 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-example.war
2008-10-15 23:23:09 org.apache.catalina.core.ApplicationContext log
信息: action: []: Verifying ModuleConfig for this module
2008-10-15 23:23:09 org.apache.catalina.core.ApplicationContext log
信息: action: []: Verification of ModuleConfig has been completed
2008-10-15 23:23:09 org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn init
信息: Initializing memory database plug in from '/WEB-INF/database.xml'
2008-10-15 23:23:09 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 23:23:09 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validation.xml'
2008-10-15 23:23:10 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-examples.war
2008-10-15 23:23:22 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 23:23:22 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator/validation.xml'
2008-10-15 23:23:43 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive tiles-documentation.war
2008-10-15 23:23:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module ''.
2008-10-15 23:23:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/tutorial'.
2008-10-15 23:23:45 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/test'.
2008-10-15 23:23:45 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/examples'.
[INFO] addressbook] - userdatabase: Initializing database servlet
---------------------------------------------------------------------------------------------------------------
有好多个module,,,module '/tutorial'.啦module '/examples'.啦 module ''.等等...而且有些validator-rules是加载成功了的..是不是说这些是struts自带的例子啊?====45 column 15:=====会不会就是因为加载例子的validaion.xml出错了?
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
也不行!而且我发现啊
--------------------------------------------------------------------------------------------------------
信息: Deploying web application archive struts-documentation.war
2008-10-15 23:23:08 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-example.war
2008-10-15 23:23:09 org.apache.catalina.core.ApplicationContext log
信息: action: []: Verifying ModuleConfig for this module
2008-10-15 23:23:09 org.apache.catalina.core.ApplicationContext log
信息: action: []: Verification of ModuleConfig has been completed
2008-10-15 23:23:09 org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn init
信息: Initializing memory database plug in from '/WEB-INF/database.xml'
2008-10-15 23:23:09 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 23:23:09 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validation.xml'
2008-10-15 23:23:10 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-examples.war
2008-10-15 23:23:22 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 23:23:22 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator/validation.xml'
2008-10-15 23:23:43 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive tiles-documentation.war
2008-10-15 23:23:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module ''.
2008-10-15 23:23:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/tutorial'.
2008-10-15 23:23:45 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/test'.
2008-10-15 23:23:45 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/examples'.
[INFO] addressbook] - userdatabase: Initializing database servlet
---------------------------------------------------------------------------------------------------------------
有好多个module,,,module '/tutorial'.啦module '/examples'.啦 module ''.等等...而且有些validator-rules是加载成功了的..是不是说这些是struts自带的例子啊?====45 column 15:=====会不会就是因为加载例子的validaion.xml出错了?
#22
你说的那些'/tutorial'啦'/examples'之类的,的确是人家给的例子,但那些例子不太可能会出错吧?
网上交流有很多不便,给个建议:从你身边找个会的人,手把手地教你一次,肯定就学会了。
或者,可以先把这个问题放一放,等积累了更多知识的时候,没准哪一天,你突然就明白了、掌握了。
网上交流有很多不便,给个建议:从你身边找个会的人,手把手地教你一次,肯定就学会了。
或者,可以先把这个问题放一放,等积累了更多知识的时候,没准哪一天,你突然就明白了、掌握了。
#23
哦~身边的人都学c++,我自学的java,没人指路确实好郁闷的,看来也只好先放一放了......
#24
强烈关注中,我这里也出现同样的问题
#25
我也出现这个问题,项目在别人机上好好的~过来我的机子上就显示不配对
#1
严重: Parse Error at line 45 column 15: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
45行15列的“formset”元素不完全全
45行15列的“formset”元素不完全全
#2
的确是validation.xml文件的问题。
<formset>中至少得有一个<form>元素,你仔细检查一下,是否写错了?
<formset>中至少得有一个<form>元素,你仔细检查一下,是否写错了?
#3
validation.xml是myeclipse自动生成的呀...
#4
你是不是动里面的东西了?
#5
我知道了,你可能压根儿就没往这里边写东西,甚至压根儿就没打开看过,是吗?
你得往里边写验证规则呀,呵呵。
#6
强悍!你说对了,我不知道还要往里边写东西的呢,不过..我的myeclipse里只有validator-rules.xml啊,找不着validation.xml~~,是不是要自己建一个的啊?
#7
是的 不然没法调用ActionForm 中的Validate方法
如果你想做验证的话,建议还是用 JavaScript吧
不然配置 Validation.xml 很繁琐的
如果你想做验证的话,建议还是用 JavaScript吧
不然配置 Validation.xml 很繁琐的
#8
书上说validation_1_1.dtd描述了validation.xml....可是我validation到处都找不到,我想就自己建一个吧,可那个用来约束的dtd怎么写?myeclipse里自动生成的valitior-rules.xml的前两句是<!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">
而我旧书上说是validator-rules_1_1.dtd定义validatior-rules.xml的...是不是把"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd"改成"http://jakarta.apache.org/commons/dtds/validator_1_1.dtd"就行了?
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
而我旧书上说是validator-rules_1_1.dtd定义validatior-rules.xml的...是不是把"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd"改成"http://jakarta.apache.org/commons/dtds/validator_1_1.dtd"就行了?
#9
改了还不行呀~~怎么还是报这个错??信息: Loading validation rules file from '/WEB-INF/validation.xml'
2008-10-15 0:11:30 org.apache.commons.digester.Digester error
严重: Parse Error at line 45 column 15: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
org.xml.sax.SAXParseException: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
连行列都一样的!可是我的validation.xml'总共都没有45行呢!!怎么回事?
2008-10-15 0:11:30 org.apache.commons.digester.Digester error
严重: Parse Error at line 45 column 15: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
org.xml.sax.SAXParseException: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
连行列都一样的!可是我的validation.xml'总共都没有45行呢!!怎么回事?
#10
2008-10-15 0:21:42 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: G:\eclipse\jdk1.5.0_06\bin;C:\Tomcat 5.5\bin
2008-10-15 0:21:42 org.apache.coyote.http11.Http11BaseProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2008-10-15 0:21:42 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1156 ms
2008-10-15 0:21:43 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2008-10-15 0:21:43 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/5.5.27
2008-10-15 0:21:43 org.apache.catalina.core.StandardHost start
信息: XML validation disabled
2008-10-15 0:21:44 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-blank.war
2008-10-15 0:21:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module ''.
2008-10-15 0:21:44 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 0:21:44 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validation.xml'
2008-10-15 0:21:45 org.apache.commons.digester.Digester error
严重: Parse Error at line 45 column 15: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
org.xml.sax.SAXParseException: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
它凭什么总是报这个错??!!还总是line 45 column 15的!可是validation.xml是这样的:<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validation_1_1.dtd">
<form-validation>
<formset>
<form name="HelloForm">
<field property="userName" depends="my">
<msg name="userName" key="hello.no.username.error" resource="true"/>
</field>
</form>
</formset>
</form-validation>
我怀疑它加载的根本就不是我自己写的这个validation.xml啊!怎么回事~~?前辈们???help~~
信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: G:\eclipse\jdk1.5.0_06\bin;C:\Tomcat 5.5\bin
2008-10-15 0:21:42 org.apache.coyote.http11.Http11BaseProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2008-10-15 0:21:42 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1156 ms
2008-10-15 0:21:43 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2008-10-15 0:21:43 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/5.5.27
2008-10-15 0:21:43 org.apache.catalina.core.StandardHost start
信息: XML validation disabled
2008-10-15 0:21:44 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-blank.war
2008-10-15 0:21:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module ''.
2008-10-15 0:21:44 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 0:21:44 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validation.xml'
2008-10-15 0:21:45 org.apache.commons.digester.Digester error
严重: Parse Error at line 45 column 15: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
org.xml.sax.SAXParseException: The content of element type "formset" is incomplete, it must match "(constant*,form+)".
它凭什么总是报这个错??!!还总是line 45 column 15的!可是validation.xml是这样的:<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validation_1_1.dtd">
<form-validation>
<formset>
<form name="HelloForm">
<field property="userName" depends="my">
<msg name="userName" key="hello.no.username.error" resource="true"/>
</field>
</form>
</formset>
</form-validation>
我怀疑它加载的根本就不是我自己写的这个validation.xml啊!怎么回事~~?前辈们???help~~
#11
在MyEclipse中,validation.xml得自己创建,其DTD与validator-rules.xml完全相同,复制过来即可,千万不要去改。
把你写的validation.xml的内容贴出来,然后发则消息给我,给你看看。
你的ActionForm继承的是哪个类?把它的源码全贴出来。
把struts-config.xml中的<plug-in>也贴出来,都检查一下。
把你写的validation.xml的内容贴出来,然后发则消息给我,给你看看。
你的ActionForm继承的是哪个类?把它的源码全贴出来。
把struts-config.xml中的<plug-in>也贴出来,都检查一下。
#12
哦,我看到你贴出来的validation.xml了。
我料你还不会写自定义验证器,那depends="my"肯定有问题。
你想做非空验证的话,应该写成:
depends="required"
但是现在这不是关键问题。
你把那个改过的DTD先删了,从validator-rules.xml中再次复制它的DTD过来,粘validation.xml上头,不要改版本了,再试试。
你是用MyEclipse吧?
如果你想用validator1.1,你就换成Struts1.2试试。
我料你还不会写自定义验证器,那depends="my"肯定有问题。
你想做非空验证的话,应该写成:
depends="required"
但是现在这不是关键问题。
你把那个改过的DTD先删了,从validator-rules.xml中再次复制它的DTD过来,粘validation.xml上头,不要改版本了,再试试。
你是用MyEclipse吧?
如果你想用validator1.1,你就换成Struts1.2试试。
#13
=================我的ActionForm==============
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
#14
=================我的ActionForm==============
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
#15
=================我的ActionForm==============
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
package com.yourcompany.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.action.ActionMapping;
public final class HelloForm extends ValidatorForm {
private String userName = null;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void reset(ActionMapping mappijng,HttpServletRequest request){
userName=null;
}}
===================================================================================
难道它有默认的validation.xml??可是在哪也找不到呀! 我自己还在struts-config.xml里加了这句呢: <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
应该没错吧?.......
=====================================================================================
关于depends="my"是因为我在validator-rules.xml里有</validator>
<validator methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,org.apache.struts.action.ActionErrors,javax.servlet.http.HttpServletRequest" name='my' classname="package com.yourcompany.struts.Check" msg=""
method="validateMonster">
</validator>
我用的是myeclipse+struts1.1 1.1不行吗?干嘛要用1.2?
#16
嗯……ActionForm没问题,插件的配置没问题。
你还自己写了个验证器(恰好超出我的意料),真强!
从你发上来的代码,没看出什么问题。
你不一定要用Struts1.2,这一点我之前说的很明白:
如果你想用validator1.1,你就换成Struts1.2试试。
之所以提这个建议,是因为你书上的代码用的是validator1.1,而MyEclipse中Struts1.1中的validator的版本为1.0,跟你书上的代码的版本不一样。而validator框架,1.0和1.1是有很大区别的,他们的DTD、配置文件不可以混用,自定义验证器的写法也不一样。
当然使用Struts1.1是可以做出来的,但是你现在还只会照着书做,所以我才建议你用Struts1.2,是因为它带的validator是1.1的版本,用起来,跟书上的代码贴近些。换句话说,你成功的可能性更高一些。
看你很不情愿,那就算啦。算我多事。呵呵。
你还自己写了个验证器(恰好超出我的意料),真强!
从你发上来的代码,没看出什么问题。
你不一定要用Struts1.2,这一点我之前说的很明白:
如果你想用validator1.1,你就换成Struts1.2试试。
之所以提这个建议,是因为你书上的代码用的是validator1.1,而MyEclipse中Struts1.1中的validator的版本为1.0,跟你书上的代码的版本不一样。而validator框架,1.0和1.1是有很大区别的,他们的DTD、配置文件不可以混用,自定义验证器的写法也不一样。
当然使用Struts1.1是可以做出来的,但是你现在还只会照着书做,所以我才建议你用Struts1.2,是因为它带的validator是1.1的版本,用起来,跟书上的代码贴近些。换句话说,你成功的可能性更高一些。
看你很不情愿,那就算啦。算我多事。呵呵。
#17
15楼说的不错!~!
也算我多事哈!~!你应该采取他的建议!~!
对你很有好处的!~!呵呵
也算我多事哈!~!你应该采取他的建议!~!
对你很有好处的!~!呵呵
#18
疯了疯了,快疯了!!啊~~我用了1.2的可是还不行 就连出错的位置都是Error at line 45 column 15!每次都是这样,
===================================下面是我的验证处理类===========有错吗?====================
package com.yourcompany.struts;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.Field;
import org.apache.commons.validator.util.ValidatorUtils;
import org.apache.commons.validator.ValidatorAction;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionMessage;
public class Check implements Serializable {
public static boolean validateMonster(Object bean,
ValidatorAction va,Field field,
ActionMessages errors,
HttpServletRequest request){
String userName = ValidatorUtils.getValueAsString(bean, field.getProperty());
if(userName==null||userName.length()<1)
errors.add("username", new ActionMessage("hello.no.username.error"));
return (errors.isEmpty());
}
}
===================================下面是我的验证处理类===========有错吗?====================
package com.yourcompany.struts;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.Field;
import org.apache.commons.validator.util.ValidatorUtils;
import org.apache.commons.validator.ValidatorAction;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionMessage;
public class Check implements Serializable {
public static boolean validateMonster(Object bean,
ValidatorAction va,Field field,
ActionMessages errors,
HttpServletRequest request){
String userName = ValidatorUtils.getValueAsString(bean, field.getProperty());
if(userName==null||userName.length()<1)
errors.add("username", new ActionMessage("hello.no.username.error"));
return (errors.isEmpty());
}
}
#19
顺便问一下...对表单字段的验证 我是不是可以直接放在ActionForm里的validate()方法里啊?我干脆不用validator框架就行啦~
可是我每次add struts capabilities时 就自动生成了validator-rules.xml了 而且就算我不去配置它也不新建vaildation.xml,当启动tomcat时 也会自动加载vaildation.xml和validator-rules.xml的..所以我想啊 它每次都是line 45 column 15这里出错了 会不会是因为它压根就没当我写的vaildation.xml的存在?然后加载一个默认的vaildation.xml?可是我找不到哪里还有vaildation.xml...扯远了,回到原来话题..我如果不用validator框架行不行的啊?怎么做才不会自动生成validator-rules.xml呢?我试过把它生成的validator-rules.xml删了然后启动tomcat的 可是它还会再次生成那讨厌的validator-rules.xml!!!
可是我每次add struts capabilities时 就自动生成了validator-rules.xml了 而且就算我不去配置它也不新建vaildation.xml,当启动tomcat时 也会自动加载vaildation.xml和validator-rules.xml的..所以我想啊 它每次都是line 45 column 15这里出错了 会不会是因为它压根就没当我写的vaildation.xml的存在?然后加载一个默认的vaildation.xml?可是我找不到哪里还有vaildation.xml...扯远了,回到原来话题..我如果不用validator框架行不行的啊?怎么做才不会自动生成validator-rules.xml呢?我试过把它生成的validator-rules.xml删了然后启动tomcat的 可是它还会再次生成那讨厌的validator-rules.xml!!!
#20
错。如果你不配置这个
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
那么validator-rules.xml是不会被用到的(自然也就不会出问题了)。换句话说,如果你不打算使用验证器框架,你可以对它视而不见。
看样子,也只好这样了……就用validate()方法完成验证吧,呵呵。
#21
不行啊!去掉了<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
也不行!而且我发现啊
--------------------------------------------------------------------------------------------------------
信息: Deploying web application archive struts-documentation.war
2008-10-15 23:23:08 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-example.war
2008-10-15 23:23:09 org.apache.catalina.core.ApplicationContext log
信息: action: []: Verifying ModuleConfig for this module
2008-10-15 23:23:09 org.apache.catalina.core.ApplicationContext log
信息: action: []: Verification of ModuleConfig has been completed
2008-10-15 23:23:09 org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn init
信息: Initializing memory database plug in from '/WEB-INF/database.xml'
2008-10-15 23:23:09 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 23:23:09 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validation.xml'
2008-10-15 23:23:10 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-examples.war
2008-10-15 23:23:22 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 23:23:22 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator/validation.xml'
2008-10-15 23:23:43 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive tiles-documentation.war
2008-10-15 23:23:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module ''.
2008-10-15 23:23:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/tutorial'.
2008-10-15 23:23:45 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/test'.
2008-10-15 23:23:45 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/examples'.
[INFO] addressbook] - userdatabase: Initializing database servlet
---------------------------------------------------------------------------------------------------------------
有好多个module,,,module '/tutorial'.啦module '/examples'.啦 module ''.等等...而且有些validator-rules是加载成功了的..是不是说这些是struts自带的例子啊?====45 column 15:=====会不会就是因为加载例子的validaion.xml出错了?
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
也不行!而且我发现啊
--------------------------------------------------------------------------------------------------------
信息: Deploying web application archive struts-documentation.war
2008-10-15 23:23:08 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-example.war
2008-10-15 23:23:09 org.apache.catalina.core.ApplicationContext log
信息: action: []: Verifying ModuleConfig for this module
2008-10-15 23:23:09 org.apache.catalina.core.ApplicationContext log
信息: action: []: Verification of ModuleConfig has been completed
2008-10-15 23:23:09 org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn init
信息: Initializing memory database plug in from '/WEB-INF/database.xml'
2008-10-15 23:23:09 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 23:23:09 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validation.xml'
2008-10-15 23:23:10 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive struts-examples.war
2008-10-15 23:23:22 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator-rules.xml'
2008-10-15 23:23:22 org.apache.struts.validator.ValidatorPlugIn initResources
信息: Loading validation rules file from '/WEB-INF/validator/validation.xml'
2008-10-15 23:23:43 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive tiles-documentation.war
2008-10-15 23:23:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module ''.
2008-10-15 23:23:44 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/tutorial'.
2008-10-15 23:23:45 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/test'.
2008-10-15 23:23:45 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
信息: Tiles definition factory loaded for module '/examples'.
[INFO] addressbook] - userdatabase: Initializing database servlet
---------------------------------------------------------------------------------------------------------------
有好多个module,,,module '/tutorial'.啦module '/examples'.啦 module ''.等等...而且有些validator-rules是加载成功了的..是不是说这些是struts自带的例子啊?====45 column 15:=====会不会就是因为加载例子的validaion.xml出错了?
#22
你说的那些'/tutorial'啦'/examples'之类的,的确是人家给的例子,但那些例子不太可能会出错吧?
网上交流有很多不便,给个建议:从你身边找个会的人,手把手地教你一次,肯定就学会了。
或者,可以先把这个问题放一放,等积累了更多知识的时候,没准哪一天,你突然就明白了、掌握了。
网上交流有很多不便,给个建议:从你身边找个会的人,手把手地教你一次,肯定就学会了。
或者,可以先把这个问题放一放,等积累了更多知识的时候,没准哪一天,你突然就明白了、掌握了。
#23
哦~身边的人都学c++,我自学的java,没人指路确实好郁闷的,看来也只好先放一放了......
#24
强烈关注中,我这里也出现同样的问题
#25
我也出现这个问题,项目在别人机上好好的~过来我的机子上就显示不配对