如何在删除之前将以下代码重定向到以前的网页?

时间:2014-04-17 19:13:53

标签: java jsp

在下面的删除后,如何将此页面重定向到预览页面并进行刷新以不显示删除的数据?

我尝试了一些选项:

<%
    String redirectURL = "Index.jsp";
    response.sendRedirect(redirectURL);
%>

但没有奏效。它应该与完整的网址一起使用吗? 我也是这样做的,或者这不是最好的做法吗?

谢谢!

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page language="java"%>
<%@page import="java.lang.*" import="org.postgresql.*"
    import="java.sql.*"%>

<!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=ISO-8859-1">
<title></title>
</head>
<body>
    <%
        try {

            Class.forName("org.postgresql.Driver");
            String url = "jdbc:postgresql://localhost:5432/postgres";
            Connection connection = DriverManager.getConnection(url,
                    "postgres", "admin");

            String strquery = "DELETE FROM projects WHERE project = '"
                    + request.getParameter("project") + "'";

            Statement st = connection.createStatement();

            //System.out.println("Connecting to database...");
            ResultSet rs = st.executeQuery(strquery);

            System.out.println(strquery);

            pageContext.forward("Index.jsp");

            rs.close();
            st.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    %>
</body>
</html>

0 个答案:

没有答案