views:

32

answers:

2

I have a String field in the DB (mySQL) and on click of a button on a JSP page I want to download the contents of that field to a file on the client machine.

The client can give a name or a default name I should be able to give.

My server is tomcat.

A: 

Basically :

  1. Create Java class for stored object, make it serializable
  2. Map DB table to your Java class (use JPA or Hibernate or raw JDBC)
  3. Write object to File using ObjectOutputStream, you can ask for name, use for example JFileChooser or something similar
Xorty
+2  A: 

I would just link the JSP to a servlet that sets a content disposition header then just prints out the value of the DB field

response.setHeader("Content-disposition","attachment; filename=something.txt" );
Rob Cooney
I'm using struts, how can I give the filename as dynamic, I tried a lot o tricks, but am doing something wrong. Also is there a way for the client to enter a files name of his own?
Panther24
I don't know struts, but it seems like you should be able to just make the filename into a string variable and have the user pass the desired name in a form field before they click the download button.
Rob Cooney