Java 输出流到网页
我正在为一些服务器测试编写一个非常粗糙的web界面 我的servlet代码基本上如下所示:Java 输出流到网页,java,html,http,tomcat,servlets,Java,Html,Http,Tomcat,Servlets,我正在为一些服务器测试编写一个非常粗糙的web界面 我的servlet代码基本上如下所示: import Application.*; @WebServlet("/runtest") public class RunTestServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExceptio
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>";
}
}
导入应用程序。*;
@WebServlet(“/runtest”)
公共类RunTestServlet扩展了HttpServlet{
受保护的void doGet(HttpServletRequest请求、HttpServletResponse响应)
抛出ServletException、IOException{
response.setContentType(“text/html”);
PrintWriter out=response.getWriter();
out.println(View.runTestPageHTML());
}
受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应)引发ServletException、IOException{
Application.runTest();
doGet(请求、响应);
}
}
类视图{
公共静态字符串runTestPageHTML(){
返回“”;
}
}
这有两个问题。如果表单被重新发送,Tomcat可以并且将开始一个新的作业,并且没有关于作业进度的反馈
我基本上希望Application.runTest()将所有的访问重新路由到
http:///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;
}
}
}