大佬教的,做个笔记
方法一(推荐):
新建一个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”
在服务器控制台输入命令:jinfo -sysprops
此贴终结