大佬教的,作個筆記
方法一(推薦):
新建一個jsp頁面在webapp下
而後添加
<%
out.print(System.getProperties().getProperty("file.encoding"));
%>
訪問便可
方法二:打印到文件
//Spring管理類中獲取requets.attributes
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attrs == null) {
// throw new IllegalStateException("當前線程中不存在 Request 上下文");
}else{
//信息源
Properties properties = System.getProperties();
//獲取真實項目路徑('.../webapps' + '/images/testLog.txt')
String logRealPath = attrs.getRequest().getServletContext().getRealPath("/images/testLog.txt");
//開啓流
OutputStream out=new FileOutputStream(logRealPath,true);
//拿到系統信息
Set<Map.Entry<Object, Object>> entries = properties.entrySet();
//打印到文件當中
for (Map.Entry entry:entries
) {
out.write(entry.getKey().toString().getBytes("UTF-8"));
out.write("-->".getBytes("UTF-8"));
out.write(entry.getValue().toString().getBytes("UTF-8"));
out.write("\n".getBytes("UTF-8"));
}
//關閉流
out.close();
}
//瀏覽器輸入項目路徑/images/testLog.txt查看
查找「file.encoding」