Sohalia,
You can't call both getOutputStream() and getWriter(). You can only call
one or the other. It is documented in the JavaDocs.
I don't think you need the call to getWriter().
-Richard
At 12:23 PM 9/26/01 -02-30, you wrote:
>Hello
>I want a servlet to force a download after the user has selected a
>filename from my applet. The user selects a filename from the list of
>files they have saved in their database account. The file is saved as a
>longblob in mysql database. What the following code is suppose to do is
>get the blob from the data base, turn it into a File and then download the
>file, but I get an error java.lang.IllegalStateException: can't mix text
>and binary input
>and this error apparantly happens at the line that PrintWriter out2 = ..
>is on.
>
>--------------------------
> ObjectInputStream in = new ObjectInputStream(req.getInputStream() );
> ObjectOutputStream out1 = new ObjectOutputStream(
> resp.getOutputStream() );
> PrintWriter out2 = resp.getWriter();
> try {
>
> String url = "jdbc:mysql://localhost/imsg";
> try {
> //get parameters from applet
> UserData data = (UserData)in.readObject();
> //Connect to database
> Class.forName("org.gjt.mm.mysql.Driver").newInstance();
> Connection con = DriverManager.getConnection(url,
>"username", "passwdA");
> //create statement
> Statement stmt = con.createStatement();
> //submit query
> ResultSet rs = stmt.executeQuery
> ("SELECT * FROM file WHERE
>user_to='"+data.getUserName()+"' AND fname='"+data.getFileName()+"';");
> //create File from Blob
> File f = new File(data.getFileName());
> BufferedOutputStream os = new BufferedOutputStream(new
>FileOutputStream(f));
> Blob blob = rs.getBlob("data");
> int size = (int)blob.length();
> byte[] tmp = blob.getBytes(0, size);
> os.write(tmp, 0, size);
> os.flush(); os.close();
> //automatically download file
> out2.println("Content-Disposition: attachment;
>filename="+data.getFileName());
> out2.println("Content-Length: "+f.length());
> out2.println("Content-Type: application/octet-stream;
>name="+f);
> //return true if dl successful..
> Boolean res = new Boolean("true");
> out1.writeObject(res);
> con.close();
>
>
>---------------------------
>am I completely going about this the wrong way? or am I leaving something
>out?
>
>Thanks
>Sohaila
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html