您的位置:首页 > 其它

调试精通hibernate第二章例子的问题

2008-08-03 01:04 218 查看
以web形式运行出错:java.io.CharConversionException:No an ISO 8859-1 character:以

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
try{
response.setContentType("text/html;charset=GB2312");
new BusinessService().test(this.getServletContext(),response.getOutputStream());
}catch(Exception e){e.printStackTrace();
}

out.println("------以下是"+customer.getName()+"的个人信息------"+"<br>");
out.println("ID: "+customer.getId()+"<br>");
out.println("口令: "+customer.getPassword()+"<br>");
out.println("E-Mail: "+customer.getEmail()+"<br>");
out.println("电话: "+customer.getPhone()+"<br>");
out.println("地址: "+customer.getAddress()+"<br>");
String sex=customer.getSex()=='M'? "男":"女";
out.println("性别: "+sex+"<br>");
String marriedStatus=customer.isMarried()? "已婚":"未婚";
out.println("婚姻状况: "+marriedStatus+"<br>");
out.println("生日: "+customer.getBirthday()+"<br>");
out.println("注册时间: "+customer.getRegisteredTime()+"<br>");
out.println("自我介绍: "+customer.getDescription()+"<br>");
out.println("<img src='photo_copy.gif' border=0><p>");

这样改了可行:

private void printCustomer(ServletContext context,ServletOutputStream out,Customer customer)throws Exception{
//save photo
byte[] buffer=customer.getImage();
String path=context.getRealPath("/");
FileOutputStream fout=new FileOutputStream(path+"photo_copy.gif");
fout.write(buffer);
fout.close();

OutputStreamWriter ow = new OutputStreamWriter(out,"GB2312");

ow.write("------以下是"+customer.getName()+"的个人信息------"+"<br>");
ow.write("ID: "+customer.getId()+"<br>");
ow.write("口令: "+customer.getPassword()+"<br>");
ow.write("E-Mail: "+customer.getEmail()+"<br>");
ow.write("电话: "+customer.getPhone()+"<br>");
ow.write("地址: "+customer.getAddress()+"<br>");
String sex=customer.getSex()=='M'? "男":"女";
ow.write("性别: "+sex+"<br>");
String marriedStatus=customer.isMarried()? "已婚":"未婚";
ow.write("婚姻状况: "+marriedStatus+"<br>");
ow.write("生日: "+customer.getBirthday()+"<br>");
ow.write("注册时间: "+customer.getRegisteredTime()+"<br>");
ow.write("自我介绍: "+customer.getDescription()+"<br>");
ow.write("<img src='photo_copy.gif' border=0><p>");

ow.flush() ;//不能少
ow.close() ;


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: