在 Eclipse Java EE servlet 中不输出到控制台
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18158025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In Eclipse Java EE servlet does not output to console
提问by PM 77-1
I have a simple servlet
that creates HTML with PrintWriter and writes to consolevia System.out.prinln()
in the same doGet() method.
我有一个简单的方法servlet
,它使用 PrintWriter 创建 HTML 并通过相同的 doGet() 方法写入控制台System.out.prinln()
。
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?
我在 Eclipse(Java EE 透视图)中看到了 HTML 部分,但Console View
. stdout
Eclipse 中的 servlet应该出现在哪里?
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.
如果这里有什么不同,那就是版本,Eclipse Juno、Java EE 7、GlassFish 4 服务器。
回答by Gene
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:
如何注销到控制台:右键单击您的 glassfish 并转到查看日志文件
确保控制台设置针对您的 server.log 文件:
回答by Juned Ahsan
You will find the System.out.println
outputs in your web container logs i.e in GalssFish logs.
您将System.out.println
在 Web 容器日志(即 GalssFish 日志)中找到输出。
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.
Eclipse 仅在其自己的控制台中为独立应用程序而不是 Web 应用程序打印 sysout。原因在于,Web 应用程序部署在 Web 容器中并在这些容器下运行。Eclipse 只是帮助部署应用程序的过程,但它不会在其中部署 web 应用程序。因此,您将在 Web 容器(即 glassfish)中找到日志。