单击JSP页面中的链接后,如何将请求转发到另一个JSP页面? [英] How to forward the request to another JSP page upon click of a link in a JSP page?
本文介绍了单击JSP页面中的链接后,如何将请求转发到另一个JSP页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jsp页面中有一个链接,单击链接后,如何将请求转发到另一个jsp页面.
I have a link in the jsp page, upon the link click, how can I forward the request to another jsp page.
推荐答案
如果您只想获取一个新的jsp,则只需
If you just want to GET a new jsp then simply
<a href="/jsp/newJsp.jsp">Click Here</a>
注意:到jsp的路径将从/
公用Web空间开始,该公共目录与WEB-INF
所在的目录相同
Note: the path to jsp will start from /
the public web space the same dir where WEB-INF
resides
如果您是指 forward
,则
if you mean forward
then
点击后,您将执行GET操作,所以可以说
Upon click you will perform GET operation , So lets say
您单击
<a href="/yourApp/ForwardServlet/">Click Here</a>
在web.xml中创建一个Servlet条目,并将其映射到/ForwardServlet
到ForwardServlet
并在Servlet中执行
make a Servlet entry in web.xml and map it to /ForwardServlet
to ForwardServlet
and in Servlet perform
public class ForwardServlet extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String destination = "/WEB-INF/pages/result.jsp";
RequestDispatcher rd = getServletContext().getRequestDispatcher(destination);
rd.forward(request, response);
}
}
引用:
这篇关于单击JSP页面中的链接后,如何将请求转发到另一个JSP页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文