一个简单的问题,请大家帮忙

zhouyu4574 2005-10-24 04:59:26
各位:

请问当参数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 = '系?






...全文
76 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tjh_java 2005-10-27
  • 打赏
  • 举报
回复
感觉是java字符集的问题.

写个资源文件,从里面读出来应该没问题的.
网络精灵 2005-10-24
  • 打赏
  • 举报
回复
up

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧