English 中文(简体)
删除 Mysql 数据库中的数据, 通过 servlet / jsp / jsp 来删除数据
原标题:deleting data from mysql database trough servlet / jsp

我有一个调用 MySQL 数据库的服务器。

deletePage 方法看起来是这样:

public void  deletePage(PageData delete) {
    String firstQuery ="Delete FROM pages Where ID=  "+delete.getId()+" ;";

    try {
        statement = connection.createStatement();
        statement.executeUpdate(firstQuery);
        System.out.println("Expense is deleting");

    } catch (SQLException e) {
        System.out.println("Expense isn t deleting - SQLException");
        e.printStackTrace();
    }
}

delete.jsp 如下:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Add pages</title>
    </head>
    <body>
        <form action="adminController">
            <p>
                <input type="hidden" name="operation" value="deletepage" />
                <input type="hidden" name="parentid" value="<%= request.getParameter("id") %>" />
                Enter ID of page you want to delete:<input name="id"><br>

                <input type="submit" />
            </p>
        </form>
    </body>
</html>

manadmin.jsp :

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Insert title here</title>
    </head>
    <body>
        <%= request.getAttribute("menu") %>
    </body>
</html>

if you run this code you ll see that my delete buttons stands after each page name. what i want to do is by pressing the delete button near the page to delete this page, there should be something like "are you sure you want to delete?", submit button"delete". but what i have managed to do looks like this(as in my code): whenever delete button is pressed, you have to enter id of page you want to delete, so no matter what delete button i press, it requests for id. but i just want to delete it right away. can anyone help?

最佳回答

现任总审计长 贾瓦·贾瓦

else if (operation.equals("delete")) {
    RequestDispatcher dispatcher = request.getRequestDispatcher("/delete.jsp");
    dispatcher.forward(request, response);

} else if (operation.equals("deletepage")) {
    PageData pageData = new PageData();
    pageData.setId(request.getParameter("id"));
    dao.deletePage(pageData);
    response.sendRedirect("adminController");
}

更改为

else if (operation.equals("delete")) {
    PageData pageData = new PageData();
    pageData.setId(request.getParameter("id"));
    dao.deletePage(pageData);
    response.sendRedirect("adminController");
}

您不需要第二个操作删除页,所以不需要删除。jsp

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签