struts-config.xml<?xml version="1.0" encoding="UTF-8"?>
<!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 type="tdy218.Register.Regactonform" name="Regactonform"/>
 </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings>
    <action path="/add" scope="request" type="tdy218.Register.Regaction" name="Regactonform">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/failure.jsp"/>
    </action>
  </action-mappings>
</struts-config>

解决方案 »

  1.   

    struts-config.xml 各个问题我知道怎么回事儿了,可是改好了以后没错误了,就是提交以后到add.do以后没反应了。也没报错误,貌似是没有转向
    <forward name="success" path="/success.jsp"/>
    <forward name="failure" path="/failure.jsp"/>
    <?xml version="1.0" encoding="UTF-8"?>
    <!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 type="tdy218.Register.Regactionform" name="Regactionform"/>
     </form-beans>
      <global-exceptions />
      <global-forwards />
      <action-mappings>
        <action path="/add" scope="request" type="tdy218.Register.Regaction" name="Regactionform">
        <forward name="success" path="/success.jsp"/>
        <forward name="failure" path="/failure.jsp"/>
        </action>
      </action-mappings>
    </struts-config>Regaction.java
    package tdy218.Register;
    import java.sql.*;
    import javax.servlet.http.*;
    import tdy218.Register.DatabaseConnection;
    import org.apache.struts.action.*;public class Regaction extends Action
    {
     public ActionForward register(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception
     {
     Regactionform  login = (Regactionform)form;
       String target = "failure";
        PreparedStatement ps = null;
        String sql = "insert into  register(username,password)  values(?,?)";
       
        try{
        ps = new  DatabaseConnection().getConnection().prepareStatement(sql);
        ps.setString(1,login.getUsername());
        ps.setString(2,login.getPassword());
        ps.execute();
        if((ps.getMoreResults()==false)&&(ps.getUpdateCount()==-1))
         {
          target="success";
         }
          }
        catch(Exception e)
         {
          e.printStackTrace();
         }
         finally
         {
          ps.close();
          new  DatabaseConnection().getConnection().close();
         }
       return  mapping.findForward(target);
    }
    }
      

  2.   

    public ActionForward register(ActionMapping mapping,ActionForm form,HttpServletRequestrequest,HttpServletResponse response)改成public ActionForward execute(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request, HttpServletResponse response)