跟踪程序,是不是发生SQLException异常了?

解决方案 »

  1.   

    这是用eclipse写的工程,每个文件写的都没错,贴不上来呀
      

  2.   

    单步调试, 要不在程序中+多个System.out.println()
      

  3.   

    以下是主要的代码:
    <%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*,java.io.*;" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户注册</title>
    <style type="text/css">
    <!--
    @import url("total.css");
    .STYLE1 {color: #FF0000}
    -->
    </style></head><body>
    <form name="RegisterForm" method="post" action="regist.do">
    <div align="center">
      <table width="100%" bgColor=#fef7e3>    <tr>
          <td width="433"><div align="right">&#29992;&#25143;&#21517;<span class="STYLE1">*</span></div></td>
          <td width="494"><label>
            <div align="left">
              <input name="username" type="text" size="20" maxlength="20">
              </div>
          </label></td>
        </tr>
        <tr>
          <td width="433"><div align="right">&#23494;&#30721;<span class="STYLE1">*</span></div></td>
          <td><div align="left">
            <input name="userpsw" type="password" size="20" maxlength="20">
          </div></td>
        </tr>
        <tr>
          <td width="433"><div align="right">&#30830;&#35748;&#23494;&#30721;<span class="STYLE1">*</span></div></td>
          <td><div align="left">
            <input name="reuserpsw" type="password" size="20" maxlength="20">
          </div></td>
        </tr>
        <tr>
          <td width="433"><div align="right">&#30005;&#23376;&#37038;&#20214;<span class="STYLE1">*</span></div></td>
          <td><div align="left">
            <input name="useremail" type="text" size="20" maxlength="50">
          </div></td>
        </tr>  </table>
      <input type="submit" name="Submit" value="&#27880;&#20876;">
      <input name="Submit2" type="reset" value="&#37325;&#32622;">
    </div>
    </form>
    </body>
    </html>
    /**********************************************************
    ************************************************************
    *************************************************************************/
    //Created by MyEclipse Struts
    // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.4/xslt/JavaClass.xslpackage footman;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 javax.servlet.ServletContext;
    import javax.sql.DataSource;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.sql.SQLException;
    import java.sql.Connection;
    /** 
     * MyEclipse Struts
     * Creation date: 12-06-2005
     * 
     * XDoclet definition:
     * @struts:action path="/regist" name="RegisterForm" scope="request" validate="true"
     * @struts:action-forward name="index.jsp" path="/index.jsp"
     */
    public class RegisterAction extends Action { // --------------------------------------------------------- Instance Variables // --------------------------------------------------------- Methods /** 
     * Method execute
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     */
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) {
    RegisterForm RegisterForm = (RegisterForm) form;

    //??????
    RegisterForm registerform = (RegisterForm)form;
    String username = registerform.getUsername();
    String userpsw = registerform.getUserpsw();
    String useremail = registerform.getUseremail();
    System.out.println("1");
    System.out.println(userpsw);
    System.out.println(useremail);
    //???????
    ServletContext context = servlet.getServletContext();
    DataSource datasource = (DataSource)context.getAttribute("mysqlds");
    String sql = "insert into users(username,userpsw,useremail) values('" + username+ "','" + userpsw+ "','" + useremail+ "')";

    try{
    Connection conn = datasource.getConnection();
    Statement stmt = conn.createStatement();
    int i = stmt.executeUpdate(sql);
    stmt.close();
    conn.close();
    if(i == 1){
    return (mapping.findForward("success"));
    }
    }catch(SQLException e){
    e.printStackTrace();
    }
    return (mapping.findForward("failed"));
    }}
    /************************************************************************/
    //Created by MyEclipse Struts
    // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.4/xslt/JavaClass.xslpackage footman;import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;/** 
     * MyEclipse Struts
     * Creation date: 12-06-2005
     * 
     * XDoclet definition:
     * @struts:form name="RegisterForm"
     */
    public class RegisterForm extends ActionForm { // --------------------------------------------------------- Instance Variables
    private String username = null;
    private String userpsw = null;
    private String reuserpsw = null;
    private String useremail = null;
    // --------------------------------------------------------- Methods

    public void setUsername(String username){
    this.username = username;
    }
    public void setUserpsw(String userpsw){
    this.userpsw = userpsw;
    }
    public void setReuserpsw(String reuserpsw){
    this.reuserpsw = reuserpsw;
    }
    public void setUseremail(String useremail){
    this.useremail = useremail;
    }
    public String getUsername(){
    return this.username;
    }
    public String getUserpsw(){
    return this.userpsw;
    }
    public String getReuserpsw(){
    return this.reuserpsw;
    }
    public String getUseremail(){
    return this.useremail;
    }
    }
      

  4.   

    估计是出异常了吧,为什么不设置错误页面,而只是用try...catch捕捉?
      

  5.   

    没有出异常,如果错误就return (mapping.findForward("failed"));
      

  6.   

    你的formbean中的口令字段和action中的引用的好象不同,是不是由此引起的呢?
      

  7.   

    查一下 conn,stmt是否为努null