In Eclipse Java EE servlet does not output to console

时光毁灭记忆、已成空白 提交于 2019-12-02 01:20:03

问题


I have a simple servlet that creates HTML with PrintWriter and writes to console via System.out.prinln() in the same doGet() method.

I see HTML part in Eclipse (Java EE perspective) but there is nothing in the Console View. Where should stdout from a servlet appear in Eclipse?

Code looks like this:

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


    PrintWriter out = response.getWriter();
    out.println("<h2>Hello from Applet<h2>");


    System.out.println("doGet");
}

If it makes any difference here are the versions, Eclipse Juno, Java EE 7, GlassFish 4 server.


回答1:


You will find the System.out.println outputs in your web container logs i.e in GalssFish logs.

Eclipse prints the sysout in its own console only for standalone applications and not for web applications. The reason is that, web applications are deployed in web containers and are run under those containers. Eclipse just helps that process of deploying the applicaitons but it does not deploy the webapps within it. Hence you will find the logs in the web container i.e glassfish.




回答2:


How to Log out to console: Right click on your glassfish and go to View Log File

Make sure the console setting is directed at your server.log file:



来源:https://stackoverflow.com/questions/18158025/in-eclipse-java-ee-servlet-does-not-output-to-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!