/*读取照片  
         *    
         */  
       public  HashMap  searchStudPho(String  stud_code)  throws  Exception  {  
               HashMap  hm  =  new  HashMap();  
               int  ks_h=Integer.parseInt(stud_code);  
               String  sql  =  "select  ks_h,xp  from  ks_xp  where  ks_h="+ks_h+"";  
               try  {  
                   Linkdata  db  =  new  Linkdata();  
                   conn  =  db.getConnection();  
                   ps  =  conn.prepareStatement(sql);  
                   //ps.setInt(1,  ks_h);          
                   rs  =  ps.executeQuery();  
                   //ks_h=rs.getInt(ks_h);  
                   //Integer  ks=new  Integer(ks_h);    
                   try{  
                           if(rs.next()){  
                                   hm.put("stud_code",  stud_code);  
                                 InputStream  ins=rs.getBinaryStream("xp");  
                                   hm.put("xp",  ins);  
                   }  
                   else  {  
                       hm  =  null;  
                   }  
                       }catch(SQLException  el){  
                               el.printStackTrace();  
                       }  
                         
               }catch  (Exception  e)  {  
                   hm  =  null;  
                   throw  new  Exception("SearchStudPho  Error:---"  +  e);  
               }  //外部关闭  
               finally  {  
                       if  (rs  !=  null)  {  
                               try  {  
                                   rs.close();  
                                   rs  =  null;  
                               }  
                               catch  (SQLException  e)  {  
                                   e.printStackTrace();  
                               }  
                           }  
                           if  (ps  !=  null)  {  
                               try  {  
                                   ps.close();  
                                   ps  =  null;  
                               }  
                               catch  (SQLException  e)  {  
                                   e.printStackTrace();  
                               }  
                           }  
                           if  (conn  !=  null  ¦  ¦!conn.isClosed())  {  
                               try  {  
                                   conn.close();  
                                   conn  =  null;  
                               }  
                               catch  (SQLException  e)  {  
                                   e.printStackTrace();  
                               }  
                           }  
                       }  
               return  hm;  
           }  
 
/*servlet读取相片*/  
public  void  doGet(HttpServletRequest  request,  HttpServletResponse  response)  
       throws  ServletException,  IOException  {  
 
response.setContentType("text/html");  
//PrintWriter  out  =  response.getWriter();  
studentInfo  ps  =  new  studentInfo();  
HashMap  hm  =  new  HashMap();  
System.out.println("here1");  
//输入img字段内容到in  
try  {  
     
   String  stud_code  =  request.getParameter("stud_code");  
   hm  =  ps.searchStudPho(stud_code);  
   InputStream  in  =  null;  
   System.out.println("here2");  
   if  (hm  !=  null)  {  System.out.println("here3");  
       byte[]  b  =  new  byte[1024];  
       int  len  =  0;  
       in  =  (InputStream)  hm.get("xp");System.out.println("here43333");  
       len  =  in.read(b);System.out.println("here55555555");  
       response.reset();  
       response.setContentType("image/jpeg");    
       while  (  len    !=  -1)  {  
           response.getOutputStream().write(b,  0,  len);  
       }  
       if(in!=null){    in.close();  }    
   }  
   else  {  
       byte[]  b  =  new  byte[1024];  
       int  len  =  0;  
       String  path  =  request.getSession().getServletContext().getRealPath("/")  +  
       "\\images\\nophoto.jpg";  
       in  =  new  FileInputStream(path);  
       response.reset();  
       response.setContentType("image/jpeg");  
       len  =  in.read(b);  
       while  (  len    !=  -1)  {  
               response.getOutputStream().flush();  
                 response.getOutputStream().write(b,  0,  len);  
       }  
   }  
   if(in!=null){  
           in.close();    
   }    
}  
catch  (Exception  de)  {  
   System.out.println("photo  show  error:--"  +  de);  
}