我已经定义了一个webservlet,如下所示:
@WebServlet(name = "HomeWebServlet", urlPatterns = "/")
public class HomeWebServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Content
}
}
如何将放置在index.html
文件夹中的html页面(src/main/webapp/resources
)设置为响应?
答案 0 :(得分:3)
您只是forward
向jsp页面请求
String nextJSP = "/yourJsp.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request, response);
您将问题从jsp更新为html
在这种情况下,您只需将用户重定向到goto HTML,因为src / main / webapp位于公共网站空间,直接可供用户使用
response.sendRedirect("/yourHtml.html")
或者您仍然可以将请求转发给html
String nextHTML = "/yourHtml.html";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextHTML);
dispatcher.forward(request, response);