简体   繁体   English

任务队列Java

[英]Task queue java

Hi i'm new to Task queue java API i tried a simple Example for it. 嗨,我是Task queue java API的新手,我为此尝试了一个简单的Example。 My idea is to redirect the queue file to a servlet and to print some statement in the servlet.But it doesn't work. 我的想法是将队列文件重定向到servlet并在servlet中打印一些语句,但这是行不通的。 i mapped web.xml and used default queue I didnt get any Error but the file is not redirected to servlet . 我映射了web.xml并使用了默认队列,但未收到任何错误,但文件未重定向到servlet。 this is the codee i followed 这是我遵循的编码

taskq.java
           public class taskq extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)throwsIOException {


    Queue queue = QueueFactory.getDefaultQueue();

    System.out.println("taskqueue");
    queue.add(url("/worker"));

}
    worker.java
         public class worker extends HttpServlet {

private static final long serialVersionUID = 1L;
public String s;

public void doGet(HttpServletRequest req, HttpServletResponse resp)throws IOException {
    String s="crimsom";
    System.out.println(s);
}

 }

Please Help me on this issue. 请帮助我解决这个问题。 Regards Sharun. 问候莎伦。

You should add your output to the servlet response, instead of System.out : 您应该将输出而不是System.out添加到servlet响应中:

public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
    Queue queue = QueueFactory.getDefaultQueue();

    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();

    out.println("<html>");
    out.println("<head><title>Hello world</title></head>");
    out.println("<body><h1>taskqueue</h1></body></html>");

    queue.add(url("/worker"));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM