Scott,
Thanks. We already have this functionality in Turbine, but I will forward
it to James Li who was originally assigned this piece.
Cheers,
Todd V.
-----Original Message-----
From: Scott Walter [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 07, 2001 10:20 AM
To: Todd VanderVeen
Subject: RE: saving a file on client's machine using servlets
Below is some code I have written which will take a
file that was uploaded from an html page that has the
file control on it to a servlet. The servlet then
inserts the file into a database, it can be easily
modified to save to a disk file. FYI--I use the
o'reilley package for working with fileparts within
the http header so you will need to download it from
o'reilley to get it to work.
package sitemanager.shr.upload;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.multipart.*;
import sitemanager.shr.app.AppManager;
import java.sql.*;
/**
* Description of the Class
*
*@author Scott F. Walter
*@created February 17, 2001
*/
public class UploadContent extends HttpServlet {
/**
* Description of the Method
*
*@param request Description of
Parameter
*@param response Description of
Parameter
*@exception IOException Description of
Exception
*@exception ServletException Description of
Exception
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
}
/**
* Description of the Method
*
*@param request Description of
Parameter
*@param response Description of
Parameter
*@exception IOException Description of
Exception
*@exception ServletException Description of
Exception
*/
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
MultipartParser mp = new MultipartParser(request,
1024 * 1024);
Part p = mp.readNextPart();
Connection conn = null;
byte[] fileData = null;
byte[] fileData2 = null;
try {
conn = AppManager.getConnection();
//while(p != null) {
if (p instanceof FilePart) {
ByteArrayOutputStream ba = new
ByteArrayOutputStream();
((FilePart) p).writeTo(ba);
fileData = ba.toByteArray();
PreparedStatement stmt =
conn.prepareStatement("INSERT INTO sm_banners
(filename,bannerimage) values(?,?)");
stmt.setString(1, ((FilePart)
p).getFileName());
stmt.setBytes(2, fileData);
stmt.executeUpdate();
stmt.close();
Statement stmt2 = conn.createStatement();
ResultSet rs = stmt2.executeQuery("select
bannerimage from sm_banners");
rs.next();
fileData2 = rs.getBytes(1);
}
//p = mp.readNextPart();
//}
}
catch (Exception e) {
sitemanager.util.Logger.log(e);
}
finally {
try {
conn.close();
}
catch (Exception e) {
sitemanager.util.Logger.log(e);
}
}
response.setContentType("text/html");
ServletOutputStream out =
response.getOutputStream();
out.println("the file was uploaded!");
out.close();
}
}
--- Adilakshmi Lingam <[EMAIL PROTECTED]> wrote:
> Can you please point me to some info on how to do
> that. I'm kind of a newbie
> in this area.
> thanks in advance,
> Lakshmi
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
> David Crooke
> Sent: Monday, March 05, 2001 11:28 PM
> To: [EMAIL PROTECTED]
> Subject: Re: saving a file on client's machine
> using servlets
>
>
> Sounds like a case for JavaScript, or possibly an
> applet. Pushing to the
> server and back is kinda clonky.
> If you just want them to create a file and save to
> disk, why not have them
> crank up a local text editor?
>
> "Burgess, Jay" wrote:
>
>
> I believe one solution is to POST the form data
> from the text area to
> you servlet, then return it right back, but with an
> unknown MIME type.
> Typically, browsers give you the option to "Save to
> Disk" when they
> encounter an unknown MIME type. To set the MIME type
> on the response, simply
> call "res.setContentType(type);", where "type" is
> something unknown like
> "lakshmi/post".
>
> Passing this data back and forth doesn't seem to
> be the most efficient
> solution, though, so I'm interested to see if there
> are others.
>
> Jay
>
> -----Original Message-----
> From: Adilakshmi Lingam
> [mailto:[EMAIL PROTECTED]]
> Sent: Monday, March 05, 2001 3:57 PM
> To: [EMAIL PROTECTED]
> Subject: saving a file on client's machine using
> servlets
>
> Hi,
> I have a small development question in servlets.
> If a user clicks on a button in a web
> page(servlet generated), a dialog
> box
> should appear asking him the location to save
> the content. and the
> contents
> of a text area in the web page have to be store
> in a file on the
> client's
> machine.
> Any ideas please,
> Thanks,
> Lakshmi
>
>
>
>
>
>
>
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, email:
> [EMAIL PROTECTED]
>
>
=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Scott
May the Force be with you!
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]