一个简单的问题,请大家帮忙
各位:
请问当参数LogString中含有中文字符,应该使用什么方法处理?
如果同时还要获取Session 名是UserName的值,应该怎么写?
我在第三行加入下列代码:
HttpServletRequest httpservletrequest = null ;
HttpSession session = httpservletrequest.getSession(true);
String username = (String) session.getAttribute("UserName");
我知道不应该HttpServletRequest httpservletrequest = null ;这么写。
附程序和日志结果。
public LogWrite(String LogString) {
try {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
File file = new File(df.format(new Date()) + ".log");
if (! (file.exists()))
file.createNewFile(); //如果文件不存在,创建此文件
FileOutputStream foo = new FileOutputStream( df.format(new Date()) + ".log", true); //以append方式打开创建文件
foo.write(LogString.getBytes(), 0, LogString.length()); //写入日志字符串
foo.close();
}
catch (FileNotFoundException e) {}
catch (IOException e) {}
}
数据库是:Mysql;
LogString 是:select * from Dict where RecordType = 'limit' and RecordDesc = '系统 ';
日志里的记录信息是:select * from Dict where RecordType = 'limit' and RecordDesc = '系?