我正在使用 EJB、Servlet、JSP 等编写我的第一个 Java EE 应用程序。
我使用 JBOSS 4.2 AS 和 Eclipse 作为 IDE,包括启动和停止服务器等任务。
我无法理解的是,在 jsp 中记录指令时,例如:
<% System.out.println("Log this!"); %>
按预期记录,在 Eclipse 控制台和 $SERVER_HOME/server/default/log/server.log
中,我在 servlet 内尝试过的任何类型的日志记录指令都会失败。
下面是调用 servlet 的 jsp 代码:
<form action="MyServlet" method="POST" accept-charset="utf-8">
<input type="text" name="id" value="" id="id">
<input type="submit" value="Go →">
</form>
当然还有 servlet 本身:
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public MyServlet() {
super();
System.out.println("Hi, I'm your servlet's constructor");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("Hi, this is your servlet on system.err");
System.out.println("Hi, this is your servlet on system.out");
System.out.println(request);
ServletContext sc = getServletContext();
sc.log("Hi, this is your servlet on servlet context!");
}
}
我是否遗漏了一些明显的东西?一切都做错了,或者只是看错了地方?
最佳答案
我刚刚创建了一个虚拟 Servlet,将其部署在 JBoss 4.2.3 上,并在 Eclipse 控制台和 server/default/log/server.log 中使用
所以我无法重现你的问题。肯定还有其他问题。System.out.println
输出
话虽如此,我不建议使用 System.out
或 System.err
,特别是在使用 Java EE 容器时。相反,您应该使用日志记录框架( Don't Use System.out.println! ),我建议使用 logback (log4j 的后继者)。
关于eclipse - Servlet post 请求记录到 Eclipse 控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2100849/