我用的是spring2.5,hiernate3.2,struts1.2。做一个简单的用户注册时出问题了!
applicationContext.xml
<?xml version="1.0" encoding="GB18030"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/bbs"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.connection.autocommit">true</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
   <list>
      <value>com/jun/bbs/domel/User.hbm.xml</value>
   </list>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory">
       <ref bean="sessionFactory"/>
    </property>
</bean>
<bean id="userdao" class="com.jun.bbs.dao.UserDao" abstract="true"></bean>
<bean id="userdaoimpl" class="com.jun.bbs.dao.impl.UserDaoImpl" parent="userdao">
    <property name="hibernateTemplate">
        <ref bean="hibernateTemplate"/>
    </property>
</bean>
<bean name="/jsp/user" class="com.jun.bbs.struts.action.UserAction">
        <property name="userdao">
        <ref bean="userdaoimpl"/>
     </property>
</bean>
</beans>
struts-config.xml<?xml version="1.0" encoding="GB18030"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
  <data-sources />
  <form-beans >
    <form-bean name="userForm" type="com.jun.bbs.struts.form.UserForm" />
  </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings>
    <action
      attribute="userForm"
      input="/jsp/errors.jsp"
      name="userForm"
      parameter="status"
      path="/jsp/user"
      scope="request"
      type="com.jun.bbs.struts.action.UserAction">
      <forward name="registersuccess" path="/jsp/index.jsp"/>
      <forward name="registerfailure" path="/jsp/register.jsp"/>
      </action>
  </action-mappings>
  <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"></controller>
  <message-resources parameter="com.jun.bbs.struts.ApplicationResources" />
  <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
         <set-property property="pathnames" value="/WEB-INF/validator-rules.xml"/>
  </plug-in>
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
  </plug-in>
</struts-config>问题是!能通过ActionForm中的验证!public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors  errors = new ActionErrors();
if(type == 1) {
if(this.userid == null || "".equals(this.userid)) {
errors.add("userid",new ActionMessage("user.userid.null"));
}
if(this.userpwd == null || "".equals(this.userpwd)) {
errors.add("userques",new ActionMessage("user.userpwd.null"));
} else {
if(!(this.userpwd.equals(this.confirmpwd))) {
errors.add("configpwd",new ActionMessage("user.confirmpwd.error"));
}
}
if(this.userques == null || "".equals(this.userques)) {
errors.add("userques", new ActionMessage("user.userques.null"));
}
if(this.userans == null || "".equals(this.userans)) {
errors.add("userans", new ActionMessage("user.userans.null"));
}
if(this.checkcode == null || "".equals(this.checkcode)) {
errors.add("checkcode",new ActionMessage("checkcode.null"));
}
}
return errors;
}
却不能进入到Action中去!public ActionForward register(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserForm f = (UserForm) form;
String ccode = (String) request.getSession().getAttribute("ccode");
String checkcode = f.getCheckcode();
if (!(checkcode.equals(ccode))) {
ActionMessages errors = new ActionMessages();
errors.add("checkcode", new ActionMessage("checkcode.error"));
super.saveErrors(request, errors);
return mapping.getInputForward();
}
User user = null;
try {
user = this.userdao.queryByUserid(f.getUserid());
if(user == null) {
       MD5Code md5 = new MD5Code();
       user = new User();
       user.setUserid(f.getUserid());
       user.setUserpwd(md5.getMD5ofStr(f.getUserpwd()));
       user.setUserques(f.getUserques());
       user.setUserans(f.getUserans());
       user.setSex("女");
       user.setGrade(new Integer(1));
       System.out.println("****"+f);
      this.userdao.register(user);
   request.getSession().setAttribute("userid", user.getUserid());
   request.getSession().setAttribute("grade", user.getGrade());
   return mapping.findForward("registersuccess");
} else {
ActionMessages errors = new ActionMessages();
errors.add("exist",new ActionMessage("user.userid.exist"));
super.saveErrors(request, errors);
return mapping.getInputForward();
}
} catch (Exception e) {
e.printStackTrace();
return mapping.findForward("registerfailure");
}
}控制台,没有报错!请大侠们,帮帮看看!
刚刚学完这三个框架。整合出现这问题!
没有任何提示异常,错误……
对了,用到了log4j!
谢谢!

解决方案 »

  1.   

    你的struts-config.xml 配置里面parameter="status"?
    可你Action里面的方法名是register啊,
    所以这里应该改成parameter="register"
      

  2.   

    楼上什么逻辑  那parameter搜索的是控件名好不?楼主 你再看看控制台  或者刷新下看看有没有什么出错信息  把粘上来你的代码是没什么问题的!
      

  3.   


    楼上,不好意思,你说错了,parameter="status"不是你说的意思<action
          attribute="userForm"
          input="/jsp/errors.jsp"
          name="userForm"
          parameter="status"      path="/jsp/user"
          scope="request"
          type="com.jun.bbs.struts.action.UserAction">
          <forward name="registersuccess" path="/jsp/index.jsp"/>
          <forward name="registerfailure" path="/jsp/register.jsp"/>
          </action>parameter的意思是说,
    如果你想调用某个action的某个方法,要通过parameter所指定的参数名来指明方法名。听起来有些绕,举个例子:比如你在Struts-config.xml中定义了一个Action:
    myAction
    然后,你需要访问myAction这个类的register方法,按照你上边的约定,应该在URL中输入:
    /myAction.do?status=register所以,这就是为什么struts自己带的例子,都把parameter参数设置成:method
    parameter="method"因为这样写出的URL可读性高:
    /myAction.do?method=register
      

  4.   

    sorry  看的不仔细  你的struts里的action 类型写错了  应该是type="org.springframework.web.struts.DelegatingActionProxy"
    或者  你在web.XML里加个控制器<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"></controller>
      

  5.   


    这里我确定没有问题!<input type="hidden" name="status" value="register">
      

  6.   


    改成你说的这个
    异常如下:
    严重: Servlet.service() for servlet action threw exception
    javax.servlet.UnavailableException: Cannot initialize RequestProcessor of class org.springframework.web.struts.DelegatingActionProxy: java.lang.ClassCastException: org.springframework.web.struts.DelegatingActionProxy cannot be cast to org.apache.struts.action.RequestProcessor
    at org.apache.struts.action.ActionServlet.getRequestProcessor(ActionServlet.java:595)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.jun.bbs.filter.EncodingFilter.doFilter(EncodingFilter.java:24)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
      

  7.   

    用我原来的
    控制台的内容为:
    2009-4-30 21:06:36 org.apache.catalina.core.AprLifecycleListener init
    信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_10\bin;C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin
    2009-4-30 21:06:36 org.apache.coyote.http11.Http11Protocol init
    信息: Initializing Coyote HTTP/1.1 on http-8090
    2009-4-30 21:06:36 org.apache.catalina.startup.Catalina load
    信息: Initialization processed in 567 ms
    2009-4-30 21:06:36 org.apache.catalina.core.StandardService start
    信息: Starting service Catalina
    2009-4-30 21:06:36 org.apache.catalina.core.StandardEngine start
    信息: Starting Servlet Engine: Apache Tomcat/6.0.16
    2009-4-30 21:06:43 org.apache.catalina.core.StandardContext addApplicationListener
    信息: The listener "org.springframework.web.context.ContextLoaderListener" is already configured for this context. The duplicate definition has been ignored.
    2009-4-30 21:06:44 org.apache.catalina.core.ApplicationContext log
    信息: Initializing Spring root WebApplicationContext
    INFO - Root WebApplicationContext: initialization started
    INFO - Refreshing org.springframework.web.context.support.XmlWebApplicationContext@165a3c2: display name [Root WebApplicationContext]; startup date [Thu Apr 30 21:06:44 CST 2009]; root of context hierarchy
    INFO - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
    INFO - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@165a3c2]: org.springframework.beans.factory.support.DefaultListableBeanFactory@6d0040
    INFO - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6d0040: defining beans [dataSource,sessionFactory,hibernateTemplate,userdao,userdaoimpl,/jsp/user]; root of factory hierarchy
    INFO - Hibernate 3.2.5
    INFO - hibernate.properties not found
    INFO - Bytecode provider name : cglib
    INFO - using JDK 1.4 java.sql.Timestamp handling
    INFO - Building new Hibernate SessionFactory
    INFO - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
    INFO - RDBMS: MySQL, version: 5.0.15-nt
    INFO - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.13 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
    INFO - Using dialect: org.hibernate.dialect.MySQLDialect
    INFO - Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory
    INFO - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    INFO - Automatic flush during beforeCompletion(): disabled
    INFO - Automatic session close at end of transaction: disabled
    INFO - JDBC batch size: 15
    INFO - JDBC batch updates for versioned data: disabled
    INFO - Scrollable result sets: enabled
    INFO - JDBC3 getGeneratedKeys(): enabled
    INFO - Connection release mode: auto
    INFO - Maximum outer join fetch depth: 2
    INFO - Default batch fetch size: 1
    INFO - Generate SQL with comments: disabled
    INFO - Order SQL updates by primary key: disabled
    INFO - Order SQL inserts for batching: disabled
    INFO - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    INFO - Using ASTQueryTranslatorFactory
    INFO - Query language substitutions: {}
    INFO - JPA-QL strict compliance: disabled
    INFO - Second-level cache: enabled
    INFO - Query cache: disabled
    INFO - Cache provider: org.hibernate.cache.NoCacheProvider
    INFO - Optimize cache for minimal puts: disabled
    INFO - Structured second-level cache entries: disabled
    INFO - Echoing all SQL to stdout
    INFO - Statistics: disabled
    INFO - Deleted entity synthetic identifier rollback: disabled
    INFO - Default entity-mode: pojo
    INFO - Named query checking : enabled
    INFO - building session factory
    INFO - Not binding factory to JNDI, no JNDI name configured
    INFO - Root WebApplicationContext: initialization completed in 3219 ms
    INFO - Loading validation rules file from '/WEB-INF/validator-rules.xml'
    INFO - ContextLoaderPlugIn for Struts ActionServlet 'action, module '': initialization started
    2009-4-30 21:06:47 org.apache.catalina.core.ApplicationContext log
    信息: Initializing WebApplicationContext for Struts ActionServlet 'action', module ''
    INFO - Refreshing org.springframework.web.context.support.XmlWebApplicationContext@35e6e3: display name [WebApplicationContext for namespace 'action-servlet']; startup date [Thu Apr 30 21:06:47 CST 2009]; parent: org.springframework.web.context.support.XmlWebApplicationContext@165a3c2
    INFO - Loading XML bean definitions from ServletContext resource [/WEB-INF/classes/applicationContext.xml]
    INFO - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@35e6e3]: org.springframework.beans.factory.support.DefaultListableBeanFactory@12a73d9
    INFO - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@12a73d9: defining beans [dataSource,sessionFactory,hibernateTemplate,userdao,userdaoimpl,/jsp/user]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@6d0040
    INFO - Building new Hibernate SessionFactory
    INFO - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
    INFO - RDBMS: MySQL, version: 5.0.15-nt
    INFO - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.13 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
    INFO - Using dialect: org.hibernate.dialect.MySQLDialect
    INFO - Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory
    INFO - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    INFO - Automatic flush during beforeCompletion(): disabled
    INFO - Automatic session close at end of transaction: disabled
    INFO - JDBC batch size: 15
    INFO - JDBC batch updates for versioned data: disabled
    INFO - Scrollable result sets: enabled
    INFO - JDBC3 getGeneratedKeys(): enabled
    INFO - Connection release mode: auto
    INFO - Maximum outer join fetch depth: 2
    INFO - Default batch fetch size: 1
    INFO - Generate SQL with comments: disabled
    INFO - Order SQL updates by primary key: disabled
    INFO - Order SQL inserts for batching: disabled
    INFO - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    INFO - Using ASTQueryTranslatorFactory
    INFO - Query language substitutions: {}
    INFO - JPA-QL strict compliance: disabled
    INFO - Second-level cache: enabled
    INFO - Query cache: disabled
    INFO - Cache provider: org.hibernate.cache.NoCacheProvider
    INFO - Optimize cache for minimal puts: disabled
    INFO - Structured second-level cache entries: disabled
    INFO - Statistics: disabled
    INFO - Deleted entity synthetic identifier rollback: disabled
    INFO - Default entity-mode: pojo
    INFO - Named query checking : enabled
    INFO - building session factory
    INFO - Not binding factory to JNDI, no JNDI name configured
    INFO - Using context class 'org.springframework.web.context.support.XmlWebApplicationContext' for servlet 'action'
    INFO - ContextLoaderPlugIn for Struts ActionServlet 'action', module '': initialization completed in 78 ms
    2009-4-30 21:06:48 org.apache.coyote.http11.Http11Protocol start
    信息: Starting Coyote HTTP/1.1 on http-8090
    2009-4-30 21:06:48 org.apache.jk.common.ChannelSocket init
    信息: JK: ajp13 listening on /0.0.0.0:8009
    2009-4-30 21:06:48 org.apache.jk.server.JkMain start
    信息: Jk running ID=0 time=0/32  config=null
    2009-4-30 21:06:48 org.apache.catalina.startup.Catalina start
    信息: Server startup in 11927 ms
      

  8.   

    <?xml version="1.0" encoding="GB18030"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
      <data-sources />
      <form-beans >
        <form-bean name="userForm" type="com.jun.bbs.struts.form.UserForm" />
      </form-beans>
      <global-exceptions />
      <global-forwards />
      <action-mappings>
        <action
          attribute="userForm"
          input="/jsp/errors.jsp"
          name="userForm"
          parameter="status"
          path="/jsp/user"
          scope="request"
          type="org.springframework.web.struts.DelegatingActionProxy">
          <forward name="registersuccess" path="/jsp/index.jsp"/>
          <forward name="registerfailure" path="/jsp/register.jsp"/>
          </action>
      </action-mappings>
      <message-resources parameter="com.jun.bbs.struts.ApplicationResources" />
      <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
             <set-property property="pathnames" value="/WEB-INF/validator-rules.xml"/>
      </plug-in>
      <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
        <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
      </plug-in>
    </struts-config>
    很久没弄  还是带你跑了下看看  的确是这样  改了就可以跑了:)
      

  9.   

    把你里面定义的那个<controller..>删了啊
      

  10.   

    把你里面的<controller....>删了啊,只能选择用一种方式啦
      

  11.   


    恩!楼上的改了是不报错了!但是,还是不能进入到Action中去
    org.apache.struts.action.DynaActionForm
    如果,我改成动态表单验证会出问题么。配置照上面的
      

  12.   

    还是不能进入??我的都进入了啊...
    把错误发出来.如果你改成动态表单  原理是不变的  只是修改下Action里的name=你的动态表单名就可以了  应该是没问题的
      

  13.   

    register.jsp<html:form action="jsp/user.do" method="post">
        用户ID:<html:text property="userid"></html:text><br>
        用户密码:<html:password property="userpwd"></html:password><br>
        确认密码:<html:password property="confirmpwd"></html:password><br>
        丢失密码提示问题:<html:text property="userques"></html:text><br>
        丢失密码问题答案:<html:text property="userans"></html:text><br>
        验证码:<html:text property="checkcode"></html:text>
       <img src="image.jsp"><br>
       <input type="hidden" name="status" value="register">
       <input type="hidden" name="type" value="1">
       <html:submit value="注册"></html:submit>
       <html:reset value="重置"></html:reset>
    </html:form>
    index.jsp
    <center>
         <jsp:include flush="true" page="../inc/template.jsp">
             <jsp:param name="url" value="../"/>
         </jsp:include>
         <logic:present name="userid" scope="session">
              欢迎:${userid }的光临&nbsp;
              等级:&{grade}&nbsp;
              <a href="personinfo.jsp">个人中心</a>
         </logic:present>
    web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <filter>
        <filter-name>encoding</filter-name>
        <filter-class>com.jun.bbs.filter.EncodingFilter</filter-class>
        <init-param>
            <param-name>charset</param-name>
            <param-value>gbk</param-value>
        </init-param>
    </filter>
    <context-param>
       <param-name>contextCofigLocation</param-name>
       <param-value>
                /WEB-INF/classes/applicationContext.xml
       </param-value>
    </context-param>
    <filter-mapping>
        <filter-name>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
      <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <init-param>
          <param-name>debug</param-name>
          <param-value>3</param-value>
        </init-param>
        <init-param>
          <param-name>detail</param-name>
          <param-value>3</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>所有的信息都到这里了!9楼的是运行tomcat的信息!验证码是null在Action中可以打印出来,但是,验证码错误就没有到error.jsp上去!只是,跳转了地址栏信息为:user.do谢谢你们三位的回复。尤其是,依者西也
      

  14.   

    不是很懂你的意思  也不知道你问题解决了没有  
    不过既然可以进入到Action,问题就很好办 你只需要设个断点  跟踪调试下  应该很快能找到你问题所在:)
      

  15.   


    我用了单步调试。就是不进入Action啊!运行完Action就跳到Deamo Thead!然后就完了!
      

  16.   

    你的代码应该是没什么问题的从你的错误来看  是环境配置的问题你把Tomacat里的工作文件和部署文件全部删除  重新部署  重新启动下看看如果还是不行 我也没什么办法了   毕竟看不到你的整个配置情况.
      

  17.   

    是FormBean的验证方法有问题。
    validate方法会根据你的返回值进跳转页面。如果validate返回值不为null,那struts就认为有错误,转到input页面。如果validate方法的返回值为null,struts认为验证通过,那就会跳转到Action。而你的validate方法无论验证通过没有都会返回一个ActionErrors对象,并不会在验证通过时返回一个空。建议改成如下:public ActionErrors validate(ActionMapping mapping,
                HttpServletRequest request) {
            ActionErrors  errors = new ActionErrors();
            if(type == 1) {
                if(this.userid == null || "".equals(this.userid)) {
                    errors.add("userid",new ActionMessage("user.userid.null"));
                }
                if(this.userpwd == null || "".equals(this.userpwd)) {
                    errors.add("userques",new ActionMessage("user.userpwd.null"));
                } else {
                    if(!(this.userpwd.equals(this.confirmpwd))) {
                        errors.add("configpwd",new ActionMessage("user.confirmpwd.error"));
                    }
                }
                if(this.userques == null || "".equals(this.userques)) {
                    errors.add("userques", new ActionMessage("user.userques.null"));
                }
                if(this.userans == null || "".equals(this.userans)) {
                    errors.add("userans", new ActionMessage("user.userans.null"));
                }
                if(this.checkcode == null || "".equals(this.checkcode)) {
                    errors.add("checkcode",new ActionMessage("checkcode.null"));
                }
                
                
            }        if(errors.size()>0){
                 return errors;
            }else{
                 return null;
            }
            
        }
      

  18.   

    你这有点瞎指挥了,type是要指定人家自己的类名,怎么能去用DelegatingActionProxy呢?
    那个类是跟spring整合的时候,在spring的配置文件里要定义的。
      

  19.   

    白天没时间仔细看,
    现在给出正确答案(呵呵,如果不对,再找我):1、你原来的配置基本上很好,都已经到了form验证了,说明一切没有问题,保持,
    2、如果现在已经调乱了,想办法调回去,相信你能够办到
    3、问题在你的Action的Register方法,方法签名不对
    Struts要求方法签名必须依次接收四个参数,才能调用到:
    ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response
    看样子你是自己用到哪个参数,就写了哪个,这样不对嘀,struts用类反射查不到。
    public ActionErrors validate(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
            ActionErrors  errors = new ActionErrors();
            if(type == 1) {
                if(this.userid == null || "".equals(this.userid)) {
                    errors.add("userid",new ActionMessage("user.userid.null"));
                }
                if(this.userpwd == null || "".equals(this.userpwd)) {
                    errors.add("userques",new ActionMessage("user.userpwd.null"));
                } else {
                    if(!(this.userpwd.equals(this.confirmpwd))) {
                        errors.add("configpwd",new ActionMessage("user.confirmpwd.error"));
                    }
                }
                if(this.userques == null || "".equals(this.userques)) {
                    errors.add("userques", new ActionMessage("user.userques.null"));
                }
                if(this.userans == null || "".equals(this.userans)) {
                    errors.add("userans", new ActionMessage("user.userans.null"));
                }
                if(this.checkcode == null || "".equals(this.checkcode)) {
                    errors.add("checkcode",new ActionMessage("checkcode.null"));
                }
            }
            return errors;
        }
      

  20.   


    首先我不是瞎指挥,我只是就问题分析,它这本身就是跟Struts和Spring整合,怎么不能用DelegatingActionProxy,当然还有一种方式就是用DelegatingRequestProcessor,那需要多加个控制器,我习惯用的是前者.第二,我不知道你那"正确答案"怎么正确,他那validate方法是重写的父类ActionForm的validate方法,方法签名她写的本来就是对的
    你那方法我不知道怎么会有,里面传的参数貌似action里方法的参数.它的代码我拷下来运行了  的确是能跑起来的
    你楼上那位说errors不为null也显然是不对的!
      

  21.   

    楼上那位,我所说的“错误”,并不是指会抛异常呀。validate()方法就是通过判断返回值是否为null来判断是转向到Action还是转向到input页面的。
      

  22.   

    只要validate方法return一个ActionErrors对象,就进不了Action。而这个过程是不会抛异常的,因为是完全正常的逻辑。
      

  23.   

    带你跑下验证了下,当都通过验证的时候 errors.size()=0!
      

  24.   

    你的逻辑是正确的
    可事实不是这样的,我搞不清楚ActionErrors是靠什么来标识的,也许就是size,也许里面加了个标识,也许是看里面的message是不是为空,
    但绝对不是根据为不为空返回的.
      

  25.   


    确实像“默然”所说,应该是靠NULL来判断是否有错的。
      

  26.   

    真理越辩越明,呵呵,没别的意思,你的关于DelegatingActionProxy的观点,我只能说,出发点和理论都没错,
    但确实指挥错了地方。楼主的jsp/user这个Action,是人家自己写的一个Action,所以type必须等于自己的类。而DelegatingActionProxy这个类,是spring提供的,确实要配置,但确实不是在这里。
      

  27.   

    我的代码,ActionForm和Action都没有问题,问题就出现在执行完ActionForm中的验证码是否为空,就跳到Deamo Thread中去了!
    Action中接收seesion中传来的验证码的值,和输入的对比。是否相等!就是觉得可能是那个配置出了点问题。而控制台不报异常和错误!
    我就郁闷 了!所有,问问大伙有没有遇到过!
      

  28.   

    你的Action里面要重写exeute()方法,要用动态的action,需要用参数来传递吧。
    你是用什么action?
      

  29.   

    代码应该是没问题的,你不会真像上楼说的没有继承DispatchAction吧?
      

  30.   


    敢问搂主怎么解决的?org.apache.catalina.core.StandardWrapperValve invoke
    严重: Servlet.service() for servlet action threw exception
    javax.servlet.UnavailableException: Cannot initialize RequestProcessor of class org.springframework.web.struts.DelegatingActionProxy: java.lang.ClassCastException: org.springframework.web.struts.DelegatingActionProxy cannot be cast to org.apache.struts.action.RequestProcessor
    at org.apache.struts.action.ActionServlet.getRequestProcessor(ActionServlet.java:614)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1910)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.znt.filter.EncodingFilter.doFilter(EncodingFilter.java:27)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    at java.lang.Thread.run(Thread.java:619)
    2009-12-23 1:24:58 org.apache.catalina.core.ApplicationContext log
    信息: Marking servlet action as unavailable
    2009-12-23 1:24:58 org.apache.catalina.core.ApplicationContext log
    信息: Closing WebApplicationContext of Struts ActionServlet 'action', module ''