2

I've defined a webservlet as follows:

@WebServlet(name = "HomeWebServlet", urlPatterns = "/")
public class HomeWebServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException { 
       // Content
    }

 }

How can I set as response an html page (index.html) placed in src/main/webapp/resources folder?

vdenotaris
  • 13,297
  • 26
  • 81
  • 132

1 Answers1

3

You just forward request to jsp page

String nextJSP = "/yourJsp.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request, response);

You updated question from jsp to html

in that case you just need to redirect user to goto HTML, since src/main/webapp is in public web space it would be available to user directly

response.sendRedirect("/yourHtml.html")

or you still can forward request to html

String nextHTML = "/yourHtml.html";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextHTML);
dispatcher.forward(request, response);
jmj
  • 237,923
  • 42
  • 401
  • 438