简体   繁体   English

Java Servlet-打印到Eclipse控制台

[英]Java Servlet - Print to Eclipse console

I'd like to test my servlet by printing the results to the console. 我想通过将结果打印到控制台来测试我的servlet。 System.out.println does not seen to work for a servlet. System.out.println不适用于servlet。 Does anyone know how I can achieve this? 有谁知道我怎么能做到这一点? Main purpose is for debugging at a later stage. 主要目的是在以后进行调试。

public class GetAllStaff extends HttpServlet {

private static final long serialVersionUID = 1L;

static StaffDAO dao = new StaffDAO();
static ArrayList<Staff> sList = null;

public void doGet(HttpServletRequest request,
        HttpServletResponse response)
                throws ServletException, IOException {

    sList = dao.getAllStaff();

    for (int i = 0; i < sList.size(); i++)
    {

    }
  }

You could use 你可以用

ServletContext context = getServletContext( );
context.log("This is a log item");

The logs are not printed in Eclipse console but can be found at logs folder of servlet container (say Apache Tomcat) 日志未在Eclipse控制台中打印,但是可以在servlet容器的日志文件夹中找到(例如Apache Tomcat)

Reference: http://www.tutorialspoint.com/servlets/servlets-debugging.htm 参考: http : //www.tutorialspoint.com/servlets/servlets-debugging.htm

You may want to print everything on a browser with the following code? 您可能要使用以下代码在浏览器上打印所有内容?

PrintWriter out = res.getWriter();
out.println("Some information on the browser...");

PS I tried System.out.println("something"); PS我尝试了System.out.println("something"); in my IDE (Intellij), the result showed up in the console. 在我的IDE(Intellij)中,结果显示在控制台中。

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

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