我想使用硬编码但动态的 html 响应来响应 URL 请求。
还有比下面的方法更好的方法吗?
public void doGet(HttpServletRequest request,
HttpServletResponse response)
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hola</title>");
//
}
?
最佳答案
一种方法是在 servlet 中转发响应:
getServletContext().getRequestDispatcher("mypage.html").forward(request, response);
关于java - 如何使用硬编码的 html 页面发送 servlet 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12005626/