struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Siggelkow <bills...@bellsouth.net>
Subject Re: OT: exporting data as .csv in Struts webapp
Date Wed, 07 Jul 2004 19:27:14 GMT
Ooh ... I was just reminded that the values between the commas should be
quoted in case there are internal commas ...

         out.write("\"Every\",\"good\",\"boy\",\"does\",\"fine\"\r\n");
         out.write("\"face\",\"in\",\"the\",\"space\",\"dude\"\r\n");


Bill Siggelkow wrote:

> Try something like this little servlet:
> 
> import java.io.IOException;
> import java.io.PrintWriter;
> 
> import javax.servlet.ServletException;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> 
> public class CsvServlet extends HttpServlet {
> 
>     protected void doGet(HttpServletRequest request, HttpServletResponse 
> response)
>             throws ServletException, IOException {
>         doPost(request, response);
>     }
>     protected void doPost(HttpServletRequest request, 
> HttpServletResponse response)
>             throws ServletException, IOException {
>         response.setContentType("text/csv");
>         PrintWriter out = response.getWriter();
>         out.write("Every,good,boy,does,fine\r\n");
>         out.write("face,in,the,space,dude\r\n");
>         out.flush();
>     }
> }
> 
> 
> klute wrote:
> 
>> Hi All,
>>
>> I am looking for some best practices advice on
>> handling this task:
>> I have a web application (written in Struts) that
>> talks to some database. A browser user will be able
>> user to export tabular data from the db in a comma
>> delimited file and get a save as dialog box prompting
>> to name the resulting file.
>>
>> I have not done this before so i am looking for
>> suggestions on how to accomplish it (in terms of java
>> object interaction and whatever else).
>> Thanks a lot,
>> James
>> ---
>> http://www.devbistro.com
>>
>>
>>        
>> __________________________________
>> Do you Yahoo!?
>> Read only the mail you want - Yahoo! Mail SpamGuard.
>> http://promotions.yahoo.com/new_mail 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message