문제

I have a jsp file that contains all the html and javascript that I want for my website.

Is it possible for me to create a servlet and then have the servlet reference the jsp file (instead of putting all the html into the servlet)?

Maybe something along the lines of:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  //initiate jsp file
}
도움이 되었습니까?

해결책

All you need is as below :

ServletContext context = getServletContext();
                 RequestDispatcher dispatcher = context.getRequestDispatcher("/thankYou.jsp");
                 dispatcher.forward(request,response);

or else you can set welcome-file also as jsp page in your web.xml if you dont need to instantiate Servlet first.

다른 팁

You can do it in such a simple way

RequestDispatcher rd = request.getRequestDispatcher(response
                                    .encodeURL("/file.jsp"));
                    rd.forward(request, response);

in response.encodeURL() you can pass the path to the jsp file OR simply map the jsp file in web.xml and put the mapped link to the jsp directly.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top