开发者

How to forward the request to another JSP page upon click of a link in a JSP page?

I开发者_如何转开发 have a link in the jsp page, upon the link click, how can I forward the request to another jsp page.


If you just want to GET a new jsp then simply

<a href="/jsp/newJsp.jsp">Click Here</a>

Note: the path to jsp will start from / the public web space the same dir where WEB-INF resides

if you mean forward then

Upon click you will perform GET operation , So lets say

you click

<a href="/yourApp/ForwardServlet/">Click Here</a>

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);
    }

}

Refer :

  • Servlet
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜