从servlet RequestDispatcher重定向jsp

kit*_*kid 7 jsp servlets

我想从一个servlet重定向JSP页面.所有JSP页面都在Web Content.没有under Web-INF.我有一个调用JSP页面的问题.我收到404错误.路径问题.

如何在Web Content下调用jsp页面?

ServletContext context = getServletContext();
                 RequestDispatcher dispatcher = context.getRequestDispatcher("/thankYou.jsp");
                 dispatcher.forward(request,response);
Run Code Online (Sandbox Code Playgroud)

谢谢你.

问题解决了 !

kit*_*kid 16

我用RequestDispatcher这样解决了这个问题:

RequestDispatcher requestDispatcher; 
requestDispatcher = request.getRequestDispatcher("/thankYou.jsp");
requestDispatcher.forward(request, response);
Run Code Online (Sandbox Code Playgroud)


rya*_*dlf 8

编写此代码的方式略微简洁:

request.getRequestDispatcher("/thankyou.jsp").forward(request, response);
Run Code Online (Sandbox Code Playgroud)