Java 如何通过单击提交按钮从一个 JSP 页面转到另一个页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3051298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:00:15  来源:igfitidea点击:

How to go from one JSP page to other by clicking submit button?

javajsp

提问by condinya

I want to jump from one JSP page to other JSP page by clicking submit button. How to do that in easy way?

我想通过单击提交按钮从一个 JSP 页面跳转到另一个 JSP 页面。如何以简单的方式做到这一点?

采纳答案by Bozho

  • use <form action="page2.jsp">
  • orsubmit to a servlet using <form action="targetServlet">, and then:
    • redirect to page2, using response.sendRedirect("page2.jsp")
    • orforward to page2, using request.getRequestDispatcher("page2.jsp").forward()
  • <form action="page2.jsp">
  • 或使用提交给 servlet <form action="targetServlet">,然后:
    • 重定向到 page2,使用 response.sendRedirect("page2.jsp")
    • 转发到第 2 页,使用request.getRequestDispatcher("page2.jsp").forward()