protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
....
....
getServletContext().getRequestDispatcher("/output.jsp").forward(request, response);
}
我需要的是不要在doPost
的末尾重定向到另一个JSP页面。我有一个字符串(平面文本),我需要响应它与Servlet请求。我怎么能这样做?
答案 0 :(得分:4)
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.append("Your string goes here");
out.close();
}
答案 1 :(得分:0)
//getServletContext().getRequestDispatcher("/message.jsp").forward(request, response);
response.getWriter().println(output); // output is the custom string
中找到更多信息