1
protected void doPost(HttpServletRequest request, 
            HttpServletResponse response) throws ServletException, IOException {
....
....
getServletContext().getRequestDispatcher("/output.jsp").forward(request, response);
}

我需要的是不要在doPost. 我有一个字符串(平面文本),我需要像 Servlet 请求一样响应它。我怎样才能做到这一点?

4

2 回答 2

6

你可以这样做:

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();
}
于 2012-11-15T06:50:54.160 回答
0
//getServletContext().getRequestDispatcher("/message.jsp").forward(request, response);
response.getWriter().println(output); // output is the custom string

可以从http://devzone.skillfusion.com/ajaxArticle8.php找到更多信息

于 2012-11-14T08:56:05.330 回答