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

 
以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() ;

  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值