简体   繁体   English

从 Servlet 更新 jsp 不起作用

[英]Update in jsp from Servlet not working

I have two servlets BookSaleAuction and MemberServlet and some jsp files for insert and update as index.jsp and MemberDetailUpdate.jsp and我有两个 servlet BookSaleAuction 和 MemberServlet 以及一些用于插入和更新为 index.jsp 和 MemberDetailUpdate.jsp 的 jsp 文件和
in MemberDetailUpdate.jsp在 MemberDetailUpdate.jsp 中

<form method= "post" action="/booksaleauction">
  UserName : <input type="text" name="name" value="<%=editname%>">
  Address : <input type="text" name="address" value="<%=address%>">
  Contact : <input type="tel" name="contactNo" value="<%=contact%>">
  Email : <input type="email" name="email" value="<%=editemail%>">
  <input type="hidden" name="id" value="<%=editID%>">
  <input type="hidden" name="formAction" value="update">

  <input type="submit" name="Update">
</form>

and in BookSaleAuctionServlet并在 BookSaleAuctionServlet 中

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String form = request.getParameter("formAction");
    System.out.print(form);
}

and in MemberServlet并在 MemberServlet 中

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.print("into member servlet ");
        String name = request.getParameter("name");
        String address = request.getParameter("address");
        String contact = request.getParameter("contactNo");
        String email = request.getParameter("email");
        String id = request.getParameter("id");

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("Class not found " + e);
        }
        System.out.println("JDBC Class found");
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        Statement st = null;

        try {
            con = DriverManager.getConnection("jdbc:mysql://localhost/logins", "root", "");
            String sql = "UPDATE members SET username=?, email=?, contact=?, address=? WHERE id=?";
           // ps = con.prepareStatement("UPDATE Users SET password=?, fullname=?, email=? WHERE id=id");
            PreparedStatement statement = con.prepareStatement(sql);
            statement.setString(1, name);
            statement.setString(2, email);
            statement.setString(3, contact);
            statement.setString(4, address);


            int rowsUpdated = statement.executeUpdate();
            if (rowsUpdated > 0) {
                System.out.println("An existing user was updated successfully!");
            }

        } catch (SQLException e) {
            System.out.println("SQL exception occured" + e);
        }
        try {
            request.getRequestDispatcher("MemberDetail.jsp").forward(request, response);

        } catch (Exception e) {
            System.out.println("SQL exception occured" + e);
        }

in both servlet whenever there is update done in jsp there is no any further action being done .在两个 servlet 中,只要在 jsp 中完成更新,就不会执行任何进一步的操作。 It is not working for the form even if i change action and method to run from another servlet BookSaleAuction Plz help i dont know what is the mistake i have done.即使我更改了从另一个 servlet BookSaleAuction Plz 帮助运行的操作和方法,它也不适用于表单,我不知道我BookSaleAuction误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM