我正在为一些服务器测试编写一个非常粗糙的网络界面。
我的 servlet 代码基本上是这样的:
import Application.*;
@WebServlet("/runtest")
public class RunTestServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(View.runTestPageHTML());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Application.runTest();
doGet(request,response);
}
}
class View{
public static String runTestPageHTML(){
return "<html><body><form><submit value='run'></form></body></html>";
}
}
这有两个问题。如果重新发送表单,Tomcat 可以并且将开始新的工作,并且没有关于工作进度的反馈。
我基本上希望 Application.runTest() 将所有获取重新路由到 http://<server>/runtest
logger.out 并忽略所有帖子,直到作业完成。
最佳答案
您的工作是在 Application.runTest() 中,对吗? 如果 runTest() 是静态方法,则可以使用全局变量来控制每个请求执行一次。
public class Application{
private static boolean inExecution = false;
public static void runTest(){
if(!inExecution){
inExecution = true;
//(...) yout job
inExecution = false;
}
}
}
关于java - 输出流到网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19967419/