請服用logforj java,各類java系統都會用的log套件,也有其他語言的版本…
https://blog.xuite.net/chihho32/blog/9121126-%5BJAVA%5D+Log4J
小弟補充log4j 目前最新版是這個:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
大大好:
我java寫上去就一直錯誤....
我也有import jar,也有加入xml和property了.
不知錯在哪....
Servlet.java
public class Servlet {
private static Logger logger = Logger.getLogger(Servlet.class);
public static void main(String[] args) {
BasicConfigurator.configure();
logger.info("This is an info message.");
}
謝謝
大大好:
我已經可以產生log檔了
但我試著紀錄帳號密碼
我的log或是txt都空白耶
<%@page import="java.util.logging.FileHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file = "db.jsp"%>
<%@ page import="org.apache.log4j.*" %>
<!DOCTYPE html>
<html>
<body>
<center>登入系統</br> </br>
<div class="container">
<form class="form-horizontal" action="login.jsp" method = "post">
<div class="form-group">
帳號:
<input type="account" id="acc" name="acc">
</div>
<div class="form-group">
密碼:
<input type="password" id="pwd" name="pwd">
</div>
<div class="form-group">
<button type="submit" name = "login">登入</button>
</div>
</form>
<% String acc = request.getParameter("acc");
String pwd = request.getParameter("pwd");
PropertyConfigurator.configure("../WEB-INF/log4j.properties");
Logger log = Logger.getLogger(this.getClass());
FileHandler fileHandler = new FileHandler("C:/Log/test.log");
log.info(acc+ " "+pwd);
int i;
String sql;
if(request.getParameter("login") != null )
{ sql = "select* from login where acc= '" + acc + "' and pwd= '" + pwd + "'";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
response.sendRedirect("index.jsp");
}
out.println("帳密錯誤!!");
}
%>
</div>
</body>
</html>
</html>
1.可行
2.沒有套件,自己寫
選我正解