java 跳转 动态更新页面数据

主页面include一个jsp的增删改页面,数据变动,怎么更新主页面的数据,request.getRequestDispatcher().forward(),地址栏不变,而且主页面数据也不变,
response.sendRedirect重定向到主页面地址栏变,数据更新,不是include的list页面,
该怎么做?

一般你的页面按钮,例如增加按钮,在后台处理完成后,后台页面跳转到这个查询页面来啊。即所有增、删除、改操作完成后的后台action的跳转页面都指向查询页面的jsp就可以了吧。

<%@ page language="java" import="java.util.*, java.sql.*"
import="java.text.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">






* { margin: 0; padding: 0; } body { background: url(0.jpg) no-repeat; background-position: center; margin-top: 30px; height: 500px; } #head { height: 30px; background-color: #D18B00; width: 500px; margin: 0 auto; position: relative; margin-top: 130px; margin-left: 200px; } #table { background-position: center; }

<%
    //到数据库中判断读取出的cookie中的用户名密码是否正确
    try {
        //创建路、人、桶三个对象
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        //1.加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.创建连接字符串
        String url = "jdbc:mysql://localhost:3306/information";
        //3.创建路
        conn = DriverManager.getConnection(url, "root", "");
        //4.创建人
        stmt = conn.createStatement();
        //增删改查
        //数据库添加、更新、删除数据
        //String str1="insert into book values(987,'chen',32.00)";
        //String str2="update book set price=50.00 where id=123";
        //删除的行数= ID
        out.print("已经修改的行数为:");
        out.print(request.getParameter("ID"));
        String  a = request.getParameter("ID");
        String b = request.getParameter("useName");
        String c = request.getParameter("password");
        out.println("用户名和密码是:"+b);      
        out.println("用户名和密码是:"+c);
        String str="update user set useName='"+b+"', password='"+c+"' where ID='"+a+"'";
                //i代表的是受影响行数
        int i = stmt.executeUpdate(str);
        out.print("受影响行数"+i);
        if(i==1){
            response.sendRedirect("Update.jsp");
        }
        else if(i==0){
            response.sendRedirect("Index.jsp");
        }
    } catch (Exception ex) {
        out.println(ex.toString());
    }



%>


可以用主页面和引入用的都持有的全局变量来做通知,也可以在引入页面持有主页面的函数来直接通知,直接通知的话引入页面和主页面就不解耦了。
具体如何做需要看你自己。实现方式有很多,需要你根据自己的业务选择适用的实现方式。