gpt4 book ai didi

java - 新获取数据响应重置后的 HttpServletresponse

转载 作者:太空宇宙 更新时间:2023-11-04 10:21:36 33 4
gpt4 key购买 nike

我使用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);

}

}

最佳答案

尝试一下可能会有所帮助

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);
}
}

关于java - 新获取数据响应重置后的 HttpServletresponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51082343/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com