已经配置了.xml,怎样使用..

解决方案 »

  1.   

    去看struts2的文档
    1. 你的form有没有指定validate=true
    2. 这个和xml放在什么位置也有关.
    struts2是先找Action的package的.
      

  2.   

    在struts-config.xml中加验证对应的xml
    在对应的xml(如validator-rules.xml,validation.xml)中添加对应的验证
      

  3.   

    各位看清楚了,楼主问的是Struts2,不是Struts!!!
    这个严正不需要什么struts-config.xml和validator-rules.xml,validation.xml的,当然也不需要什么form!!!
    你只需要在web.xml中配置好struts2的监听器,
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
    org.apache.struts2.dispatcher.FilterDispatcher
    </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>在struts.xml中配置好action,
    <package name="struts2" extends="struts-default">
    <action name="login" class="">
    <result name="***">/ xxx.jsp</result>
    </action>
    </package>在action中添加验证信息
    if(){
    this.addFieldError("xxx", "xxx !!!");
    }
      

  4.   

    struts2的验证可以有两方法实现
    一种是通过xml如:demo-validation.xml,要和jsp里的name对应
    另一种:在Action方法里重写validation()方法,通过addActionError,addActionMessage,addFieldError..