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

来源:互联网 发布:代驾软件哪家好 编辑:程序博客网 时间:2024/05/17 00:01
 
以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() ;

  }