我使用doGet方法获取参数,然后对其进行处理。发送答复后,它包含状态数据。同样,当第二个客户端连接时,答案包含来自第一个客户端的数据。 我要在第二个客户端连接后发送新数据。重置缓冲区并将新数据发送到第二个客户端,或者在还原页面后发送新数据。
它不起作用。客户端再次检索页面,并向我发送旧数据和新数据。我只需要将新数据发送到客户端。
class HttpTest extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HttpTest() {
super();
// TODO Auto-generated constructor stub
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
System.out.println(request.getQueryString());
String[] parameters = request.getQueryString().split(";");
String out_data="";
/*
* algorithm for generate out data
*/
out.println(out_data);
out.flush();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
答案 0 :(得分:0)
尝试一下可能会帮助
private void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
try (PrintWriter writer = response.getWriter()) {
System.out.println(request.getQueryString());
String[] parms = request.getQueryString().split(";");
String outData = "";
/*
* algorithm for generate out data
*/
writer.println(outData);
}
}