不知为什么,我用的在配置文件中设置的forward跳转不到其他页面.运行里没有错误,可以正确保存数据,但成功保存后,页面跳转不到index.jsp这个页面.有没有人能告诉我,forward不发生跳转有那几个原因造成的?
struts-config.xml配置
 <action-mappings >
      <action path="/test"
         name="LogActor" 
         scope="request" 
         input="/test.jsp"
         type="org.springframework.web.struts.DelegatingActionProxy">
      <forward name="success" path="/index.jsp" />
    </action>
控制器
package action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;import dao.ActorDao;
import orm.Actor;
import bean.LogActor;public class LogAction extends Action{

private ActorDao logindao;

public ActionForward execute(ActionMapping map, ActionForm form, 
HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionMessages errors = new ActionMessages();
String name = (String)((LogActor)form).getName();
String sex = (String)((LogActor)form).getSex();
String income = (String)((LogActor)form).getIncome();
String pbackground = (String)((LogActor)form).getPbackground();
String wexperience = (String)((LogActor)form).getWexperience();
email = new String(email.getBytes("ISO-8859-1"),"GB2312");
Actor actor = new Actor();
                actor.setName(name);
                actor.setSex(sex);
                actor.setIncome(income);
                actor.setPbackground(pbackground);
                actor.setWexperience(wexperience);
if(logindao.RegActor(actor)){
return (map.findForward("success"));
}else{
errors.add("fail_4",new ActionMessage("Register.error.d"));
saveErrors(request,errors);
return (map.getInputForward());
}
}
public ActorDao getLogindao() {
return logindao;
}
public void setLogindao(ActorDao logindao) {
this.logindao = logindao;
}
}
Hibernate和Spring共用一个配置文件,上边控制器的配置内容为
   <!-- Dao -->         
<bean id="logindao" class="dao.ActorDao">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>

<bean name="/test" class="action.LogAction" singleton="false">
<property name="logindao">
<ref bean="logindao"/>
</property>
</bean>

解决方案 »

  1.   

    struts-config.xml配置 
      <action-mappings   > 
                <action   path="/test" 
                      name="LogActor"   
                      scope="request"   
                      input="/test.jsp" 
                      type="org.springframework.web.struts.DelegatingActionProxy"> 
                <forward   name="success"   path="/index.jsp"   /> 
            </action>
    里面有問題
    attribute---屬性的formbean沒有定義  哪一個我不知道。。
    parameter---調用哪個方法沒寫  +parameter=execute
    你+上試試
      

  2.   

    建议你在控制器的程序if(logindao.RegActor(actor)){
    return   (map.findForward("success"));
    }else{
    errors.add("fail_4",new   ActionMessage("Register.error.d"));
    saveErrors(request,errors);
    return   (map.getInputForward());
    } 之前加一个打印信息,看是否执行到这一步,然后调试一下这个if{}else最终执行的是哪个,这样,才能判断是不是struts配置文件的问题,
      

  3.   

    To songhaichao1983:
        能否告诉我怎样在该开发框架下的控制器添加打印信息,判断if{}else最终执行的是哪个 
      

  4.   

    找到原因了,在DAO中的保存操作可以把数据保存到数据库,但还是执行了catch()内的代码,所以页面跳转不了,
    下边是代码.不知为什么保存数据成功,还是会执行catch()
    public boolean RegActor(Actor u){
    try{
    this.getHibernateTemplate().save(u).;
    return true;
    }
    catch(Exception e){

    return false;
    }
      

  5.   

    我不知道你的开发环境是什么,不过一般都应该有控制台或者日志输出的,或者内嵌log4j输出调试信息。
    最简单的是System.out.println("");然后看控制台是否打印,就知道执行的是那段程序。看来你找到错了,加油吧,多调试调试,貌似你对程序的调试不是很精通,加油啊。
      

  6.   

    to songhaichao1983:
         第一次做Web开发,而且是用Struts+Spring+Hibernate框架开发,System.out.println("")我会用,但是我刚开始做,未配置log4j,所以才不会调试,不过现在知道错误了,是保存数据时出误,数据可以保存到数据库,但会返回一个错误.错误提示为:javax.servlet.ServletException: org.springframework.orm.hibernate3.HibernateSystemException: Batch update returned unexpected row count from update: 0 actual row count: 7810893 expected: 1; nested exception is org.hibernate.HibernateException: Batch update returned unexpected row count from update: 0 actual row count: 7810893 expected: 1
      

  7.   

    hibernate我也不是很熟悉,估计帮不上忙了,呵呵javax.servlet.ServletException:   org.springframework.orm.hibernate3.HibernateSystemException:   Batch   update   returned   unexpected   row   count   from   update:   0   actual   row   count:   7810893   expected:   1;   nested   exception   is   org.hibernate.HibernateException:   Batch   update   returned   unexpected   row   count   from   update:   0   actual   row   count:   7810893   expected:   1
    从以上的异常中,看到, 0   actual   row,0条成功,你怎么会数据保存成功呢,仔细看看传的参数和hibernate中文件中定义的参数是否对应。