JSP按钮没有响应

时间:2018-03-26 08:23:58

标签: jsp

每当我点击"创建帐户"我的jsp页面上的按钮,没有任何事情发生。以下是表单的代码:

 <form method="post" action="" name="accountForm" id="accountForm">
                    <label for="accountName">Account Name:</label> &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="accountName" id="accountName" /> <br /> 
                    <label for="accountContact">Account Contact:</label>&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="accountContact" id="accountContact" /> <br />
                    <label for="projectId">Project Id:</label>&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="projectId" id="projectId" /> <br />
                    <label for="projectName">Project Name:</label>&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="projectName" id="projectName" /> <br />
                    <label for="ilcCode">Account Id:</label>&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="ilcCode" id="ilcCode" /> <br />
                    <label for="licenseNo">License Key:</label>&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="licenseNo" id="licenseNo" /> <br />
                    <label for="iot">IOT:</label>&nbsp;&nbsp;&nbsp;&nbsp; 
                    <select name="iot">
                    <%  while(resultset2.next()){ %>
        <option><%= resultset2.getString(1)%></option>
    <% } %>
                    </select> <br />
                    <label for="active">active:</label>&nbsp;&nbsp;&nbsp;&nbsp; <input type="checkbox" name="active">

                    <br /> <input type="button" value="Create Account" onclick="updateAccount();">
                    <input type="button" value="Search Account" onclick="searchAccount();">
                </form>

以下是updateAccount()方法的代码:

       function updateAccount()
 {
var accName = document.getElementById("accountName").value;
var accContact = document.getElementById("accountContact").value;
var projId = document.getElementById("projectId").value;
var projName = document.getElementById("projectName").value;
var ilCd = document.getElementById("ilcCode").value;
var licsnNo = document.getElementById("licenseNo").value;
var iot = document.getElementById("iot").value;
var active = document.getElementById("active").value;
 $.ajax({  
        type: "POST",  
        url: "AccountController",  
        data: {"action":"createAccount",
            "accountName":accName,"accountContact":accContact,"projectId":projId,"projectName":projName,"ilcCode":ilCd,"licenseNo":licsnNo,"iot":iot,"active":active},  
        success: function(data,jqXHR){  
            $("#accMessageDiv").html(data);
        }, 
        error: function(data,jqXHR){  
            $("#accMessageDiv").html(data);
        }, 
        beforeSend: function() {
                // setting a timeout

        },
        complete: function()
        {

        }
      }); 

 }

以下是我的AccountController类中的createAccount方法:

 protected void createAccount(HttpServletRequest request,HttpServletResponse response) throws IOException
{
    String error;

    Account account = new Account();

    account = fillAttributes(account, request);
    PrintWriter out = response.getWriter();
    HttpSession session = request.getSession();
    AccountDAO accountDAO = new AccountDAOImpl();

    int result=0;
    try {
        if(account.getAccName() != null && account.getProjectId() != null)
            result = accountDAO.createAccount(account);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

     if (account.getAccName() == null && account.getProjectId() == null ) {
        error = "Enter Valid Account Details.";

        out.write(error);
    } else {
        String msg = "Account  :"+account.getAccName() + "  successfully added. ";
        out.write(msg);
        /*session.setAttribute("message", msg);
        session.removeAttribute("error");
        response.sendRedirect("index2.jsp");*/
    }

}

以下是Account类中的fillAttributes方法:

 private Account fillAttributes(Account account,HttpServletRequest request)
{

    account.setAccName(checkNull(request.getParameter("accountName")));
    account.setAccContact(checkNull(request.getParameter("accountContact")));
    account.setProjectId(checkNull(request.getParameter("projectId")));
    account.setProjectName(checkNull(request.getParameter("projectName")));
    account.setIlcCode(checkNull(request.getParameter("ilcCode")));
    account.setLicenseNo(checkNull(request.getParameter("licenseNo")));
    account.setIot(checkNull(request.getParameter("iot")));
    account.setActive(false);

    return account;
}
private String checkNull(String input)
{
    if(StringUtils.isNotBlank(input))
        return input;
    else
        return null;

}

每当我在tomcat服务器上运行jsp时,UI都会生成,但是当我点击&#34; CreateAccount&#34;按钮,绝对没有任何反应。请帮我解决这个问题。

0 个答案:

没有答案