Java 如何将requestdispatcher发送到两个不同的jsp页面路径?

Java 如何将requestdispatcher发送到两个不同的jsp页面路径?,java,jsp,servlets,javabeans,Java,Jsp,Servlets,Javabeans,我使用JSP、beans和JDBC(MVC)制作了一个注册表 在我的servlet中,我有以下代码 if ("editRegister".equalsIgnoreCase(action)) { StudentBean user = new StudentBean(); user.setName(Name); user.setStudID(ID); user.setCourse(Course); user.setEmail(

我使用JSP、beans和JDBC(MVC)制作了一个注册表

在我的servlet中,我有以下代码

        if ("editRegister".equalsIgnoreCase(action)) {
        StudentBean user = new StudentBean();

     user.setName(Name);
     user.setStudID(ID);
     user.setCourse(Course);
     user.setEmail(Email);
            db.addRecord(Name, ID, Name, Email);
             set the result into the attribute
            request.setAttribute("StudentBean", user);
            RequestDispatcher rd;
            rd = getServletContext().getRequestDispatcher("/DisplayRegistry.jsp");
            rd = getServletContext().getRequestDispatcher("/UpdateRegistry.jsp");
            rd.forward(request, response);
基本上,我希望将requestDispatcher发送到两个jsp页面,以便在表单中显示另一个具有预定义值的表单

e、 g



但是,问题是它显示null而不是值,因为requestDispatcher只发送到一个路径。

您使用两个转发的做法毫无意义

rd = getServletContext().getRequestDispatcher("/DisplayRegistry.jsp");
rd = getServletContext().getRequestDispatcher("/UpdateRegistry.jsp")
相反,您可以将该值设置为
会话
,以便您可以在两个页面中访问它(在整个应用程序会话中)

所以

您可以从会话中获取值,并拥有一个请求调度器


希望这有帮助

因此,您需要将两个视图转发给客户端。这没有任何意义。不要调用
PrintWriter out=response.getWriter()rd.forward(请求、响应)后的code>您想要实现的目标。再解释一下。我有一个注册表,它接受用户的输入并保存到数据库中。现在我想创建另一个表单,它可以更新以前的注册表单,并且我希望以前的输入显示在文本字段中,这样用户就可以更新了,但是它在输入字段中显示null,而不是以前输入的值
rd = getServletContext().getRequestDispatcher("/DisplayRegistry.jsp");
rd = getServletContext().getRequestDispatcher("/UpdateRegistry.jsp")
HttpSession session=request.getSession(false);
session.setAttribute("StudentBean", user);