Saving a file in JSF with a servlet

Okay, here is essentially what I'm doing right now:
1. The user selects some data that they want to export (save) to a file and enters a filename into a text box.
2. The user then clicks an 'Export' button and a controller action is invoked that puts the filename and the data (as a String) into the http session.
3. On success, the controller returns a successForServlet string which a navigation rule defined in faces-config looks at and sends the page to an ExportToFile.jsp page.
4. All this jsp page does is to forward the request to my servlet.
5. The servlet picks up the filename and data from the http session and sets up the appropriate response. This causes a 'Save' dialog to be prompted to the user so that they can choose a location and such.
6. The user clicks save and the file is saved to disk.
This all works wonderfully. BUT, here is the problem...I am now out of JSF's scope since the nav rule sent the request (ultimately) to a servlet. The page that the user was on is now stale and they have to click a menu item or something to get back into JSF scope. So, what now? I've tried a few things that I won't mention here until I see what kind of suggestions I get from you guys. Thanks to anyone that can help me out. Lance.

I may not be understanding you correctly (this is very new to me), but I tried your suggestion to no avail. As I understood it, you were suggesting that I put this into my servlet. I did so in a finally block in my doPost() method. Here's the code:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String methodName = "doPost";
log_.entry(methodName);
try {
// Get a session-scoped value
HttpSession session = request.getSession();
String exportFileName = (String) session.getAttribute( "ExportEntityFileName" );
String exportString = (String) session.getAttribute( "ExportEntityText" );
response.setHeader("Pragma", "No-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition", "attachment; filename=" + exportFileName + ".txt");
response.setHeader("Context-Type", "text/html");
response.getOutputStream().write(exportString.getBytes());
} catch (Exception e) {
log_.error(e.toString());
} finally {
HttpSession session = request.getSession();
session.setAttribute("ExportEntityFileName", null);
session.setAttribute("ExportEntityText", null);
response.getOutputStream().close();
session.getServletContext().getRequestDispatcher("/appPanels/utilities/BcfExport.jsp");
log_.exit(methodName);
Something about this line:
session.getServletContext().getRequestDispatcher("/appPanels/utilities/BcfExport.jsp");
...didn't look right, so I tried this also:
session.getServletContext().getRequestDispatcher("/appPanels/utilities/BcfExport.jsp").forward(request, response);
...but that was no help either. Any more suggestions out there? I can't believe that this isn't being done by others. I mean, saving a file to disk!?!?!?!? It sounds rather elementary.
Thanks for any suggestions.

Similar Messages

  • Need help with saving Premiere files to work with any update

    Hey everybody,
    I've been editing with Premiere for a while now and I haven't really had too many issues until now. I live on campus at school and they just opened up a new Library with extensive Mac Pro editing stations, some with 4K monitors! The problem is that the school is not updating the software. So I am running the latest version on my Macbook Pro, but when I try and open the files on the library computers, it tells me something like, "Cannot open file because file was saved on a newer version." Now I know it seems obvious that I should just stick to my computer, but it's nice having a much faster editing station with 27"+ screens. Because the library is so new, they are having trouble keeping up with all the updates and they don't seem to plan on updating them except every semester. So, are there any workarounds? Can I save my files as a more multi-platform file?

    I would take your computer back to the earlier version the college uses, there are workarounds to go back versions but they are not perfect.

  • Saving a file in a with a file name containing Japanese Characters

    Hi,
    I hope some genius out there comes up with the solution to this problem
    Here it is :
    I am trying to save some files using a java program from the command console , and the file name contains japanese characters. The file names are available to me as string values from an InputStream. When I try to write to a File Object containing the japanese characters , I get something like ?????.txt . I found out that I am able to save the files using the unicode value of the java characters.
    So I realize that the trick is to convert the streaming japanese characters , character by character into their respective unicode value and then Create A File Object with that name. The problem is -> I cant find any standard method to convert these characters into their unicode values. Does anyone have a better solution ? Remember , its not writing japanese characters to a file , but creating a file with japanese characters in the file name !!!!
    Regards
    Chandu

    retrive a byte array out of the input Stream and store the values in String using the condtructor
    String(byte [] bytes, String enc)
    where encoding would be Shift_Jis for japanese I guess.
    Now to understand this concept basically all the Strings are unicode however when you are passing a byte array String has no means to know what is the encoding of the byte array, which is being used to instantiate the String value so if no encoding is specified it takes the System value which is mostly iso-8859-1. This leads to displaying ?
    However in case you know the encoding of the array specifying that in the constructor would be a real help.

  • Display saved lvm file to graph with timestamp

    Hi,
    I'm having headache displaying my data with proper time-stamping. There are so many methods to save data. here I've decided to save it as a text delimited file format as lvm. a segment of my vi screen shot is attached. I want to use this way instead of other methods is the flexibilty it offers. I will be able to add on more data to store as I develop the vi. (So I'm storing data from DAQ assistant and my calculated values.) I attached a the screenshot of the file I read too.
    I would like to use another vi to open this file and plot it to a graph/chart to display as a trending of the data acquired. Can someone pls advise mi on what is a better way for mi to do it?
    Thanks alot!
    Poh
    Solved!
    Go to Solution.
    Attachments:
    datalogging vi.JPG ‏82 KB
    logged data.JPG ‏76 KB

    Hi Krisna,
    Sorry for the late reply, I was rushing to complete my project, wasn't able to reply.
    Yes, I managed to solve it. Anyway I used such high rate in the DAQ assistant is to allow continous mode acqusition & use a software filter instead of hardware filter. however writing to file in this way - writing string into .lvm, max is 10 samples/sec. unless I use tdm (I'll then log everything).
    I wasn't able to display proper time-stamping was due to the fact that I didn't add in the start-time timestamp that's required in displaying of timestamp in waveform. I'll not be able to go down to my lab, & my machine do not have LabVIEW, so what I can do is to extract portions of my report to share.
    For the portion that I used to display graph (can be seen from the attachment), I deleted the 1st column, which is the timestamp (for spreadsheet viewing), but extracted the 1st element - the converted to DBL timestamp when I start logging in the DAQ vi (written together with the header).
    This extracted (could be seen as a bunch of numbers in the lvm file) and and converted back to timestamp type and wired to build waveform block, providing the start-time of the waveform.
    Next, I replace the use of chart with graph, as graph is suitable for plotting data acquired, and chart is better for run-time display of data. now it seemed to work fine for me, except for loading time may take a while for larger files.
    Thanks for your participation in this thread!
    Cheers!
    Poh
    Attachments:
    display graph.JPG ‏39 KB
    data.JPG ‏171 KB

  • Unusual using jsf with own servlet

    Hi, it will be useful for me within my javax.servlet.Servlet class implementation I use JSF for printing output to my ServletResponse.
    What I must to do for it?
    thanks for suggestions.

    The simplest thing would be to forward to or include the appropriate URL that is handled by JSF. If for some reason this is not acceptable you might want to take a look at the implementation of the FacesServlet. But I would encourage you to pursue the forwarding/including solution first as it will be less fragile.

  • Saving .dng files in raw with sidecar

    I loaded raw images as .dng -- edited the photos -- and am trying to export as "File Settings / Format: Original" (with the attendant side car XMP).  The export folder still contains .dng files and I do not understand what else must be done. I'm a iMac user.  Thanks for the help.
    Chuck N+13

    Chuck,
    One other method to extract the XMP from the DNG would be the following:
    In LR, Save Metadata to File on all your DNGs
    Make your DNG Files read only
    Open them in ACR (e.g. using PS)
    Make a trival change to the image and then reverse it (e.g. change WB from what it is to something else, then back)
    Click Done in ACR
    ACR will try to write the XMP data into the DNG, but because it's read only, it will write a sidecar XMP for it.
    Step 4 might not be necessary to achieve a write-back of the XMP.
    Of course, you still need to get your RAW from somewhere ...
    Beat Gossweiler
    Switzerland
    Message was edited by: b_gossweiler

  • Problems loading and saving pdf files from sites with latest version.

    On my utilities I wish to download and save pdf files of my e-bill.
    Lately when I click on getting bill, Firefox opens new tab and stops.
    with a light message in url place saying "Type a web address".
    To get around this I must do a right click on the save bill and
    select open in new window, then it opens a new copy of Firefox,
    and two tabs, with the second one asking me to use Adobe to see
    pdf file. I tell it to open and then save it and print it from the tab
    that opens with the pdf file in it. This never happened before was
    always able to just click on link and it would open new tab with
    pdf file there.

    Thanks for the replies. I don't think I was clear enough with my question.
    What I want to be able to do is to click on a PDF file in my Firefox browser and be able to save it as an Adobe PDF file, not a Preview PDF file, in any folder on my computer, rather than just the specified default location for downloads. This way I can save, for example, phone bills in the phone bills folder and bank statements in the bank statements folder without having to save them to the desktop, "Get Info" on each, and change the "Open with:" box from Preview to Adobe Reader.
    Fortunately, thanks to Michael's post, I found an add-on from Firefox that allows me to do just that: https://addons.mozilla.org/en-US/firefox/addon/636
    Thanks for your help. Now, within my Firefox browser, I can choose whether to view or download PDF files, always in Adobe rather than Preview, and when I save them I get the option to choose the location each and every time.
    MacBook Mac OS X (10.4.9)
    MacBook Mac OS X (10.4.9)

  • Saving .html files in TextEdit with OSX Lion

    HELP!!!
    Just upgraded to Lion.
    When i paste html code into TextEdit and save as .html, the moment i edit and save that same file it automatically changes the extension of the file from .html to .txt..how do i turn this off so that it saves it as .html?? in Snow Leopard it never did this.
    Many Thanks.

  • Display a file inside JSF

    Hi,
    I need to Display a file inside JSF with option to change the key of this file by a fildes.
    Do you have an example how to do it?
    Is it a servlet?
    I'm programing in a server side..
    Please help me.
    Have a best weekend!
    Yael

    yael800 wrote:
    I need to Display a file inside JSF with option to change the key of this file by a fildes.Huh? What are you saying?

  • Change file name with oreilly servlet

    I am using oreilly servlet package and I want to change the file name to the file I am uploading, is this possible ?
    How ?
    Thanks.
    here I post the servlet code:
    package com.reducativa.sitio.servlets;
    * DemoParserUploadServlet.java
    * Example servlet to handle file uploads using MultipartParser for
    * decoding the incoming multipart/form-data stream
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import com.oreilly.servlet.multipart.*;
    public class DemoParserUploadServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    response.setContentType("text/plain");
    out.println("Demo Parser Upload Servlet");
    File dir = new File("f:/");
    if (! dir.isDirectory()) {
    throw new ServletException("Supplied uploadDir " + "f:/ " +
    " is invalid");
    try {
    MultipartParser mp = new MultipartParser(request, 10*1024*1024); // 10MB
    Part part;
    while ((part = mp.readNextPart()) != null) {
    String name = part.getName();
    if (part.isParam()) {
    // it's a parameter part
    ParamPart paramPart = (ParamPart) part;
    String value = paramPart.getStringValue();
    out.println("param; name=" + name + ", value=" + value);
    else if (part.isFile()) {
    // it's a file part
    FilePart filePart = (FilePart) part;
    String fileName = filePart.getFileName();
    if (fileName != null) {
    // the part actually contained a file
    long size = filePart.writeTo(dir);
    out.println("file; name=" + name + "; filename=" + fileName +
    ", filePath=" + filePart.getFilePath() +
    ", content type=" + filePart.getContentType() +
    ", size=" + size);
    else {
    // the field did not contain a file
    out.println("file; name=" + name + "; EMPTY");
    out.flush();
    catch (IOException lEx) {
    this.getServletContext().log("error reading or saving file");
    }

    Hi there,
    I am facing the same problem that you have stated in your Feb 26, 2002 10:28 AM message regarding "change file name with oreilly servlet", I would like to change the file name to include a unique identifier upon upload, did you ever find a solution to your problem?
    Thanks!
    Todd
    [email protected]

  • File Server Slowdown with Illustrator(only) saving and opening

    Hello,
    I have a problem i have been struggling with for years.
    When we save a file to the server, the time to open, save or export can be anywhere from 1-5 minutes. Its killing our productivity.
    I have changed out every component. We have Eight illustrator CS3 13.0.2 users on C2D/i3/i7 iMacs running 10.6.7. They are connecting to a Mac 10.6.7 Server with AFP - mac mini 2.53 with a lacie 5 drive raid.
    We have had this problem going back to at least 10.4.6 i think it was.  (I did not write good troubleshooting logs back then)
    What appears to be happening:
    open a file in the finder or in illustrator
    if a font is missing, it immedialy pings you, so its like illustrator looks at the files and then is looking for something else  (problem exists if no fonts are present)
    the mouse then beach balls and illustrator shows as not responsive
    the server shows some activity on the cpu/network/hard drive side but its very minor. like a get info command on lots of files
    local user shows very little to no activity
    then it stops doing nothing after the few minutes and it opens quickly.
    the content of the files does not effect the problem. A 10 meg files with lots of stuff takes maybe 4 minutes vs 3 min 50 seconds for a empty file
    my solution so far:
    I can clear the problem by running a script that deletes the illustrator prefs, mediabrowser.plist, deletes illustrator cache files, deletes apple quarantie events, bridge prefs. and a restart. Then files open in under 5 seconds. After a couple of hours or some times a day, the open times creep up to a minute, after a few days, they are 2-5 minutes.  Sometime clearing these files does not work and i have to then wipe a machine and do clean installs of everything.  Some Macs will not have the problem, and function great for a month and then they have the problem for no explainable reason.
    All other functions work great, no problems anywhere with anything else, excempt saving illustrator files to the server.
    We have tried moving the files locally and then copying them back, but we loose too much work with the errors associated with version control problems. Also a synced folder to the local machines of the server (yes that was intense on the machines) some how had the problem follow it on some macs but not others
    I have tried illustrator CS4 and CS5 and it has the same problem
    I am currently trying to brute force attack the problem, I figure i can reduce the wait time to maybe 20% with a Mac pro and a bank of SSD's. my cost is almost 8k. I am not happy giving up on fixing the bug, but we have at least 1-2 people waiting around at any given time. 
    Any thoughts on the problem or a solution?

    To create a new Swatches panel to store pattern swatches you have to:
    a) Open the Swatches panel and delete all the swatches that you don't want (optional)
    b) Choose Save Swatch Library as AI (not ASE) from the Swatches panel menu (I suggest you to save it on the Desktop! So you can easily find that!).
    The saved file is actually a simple (blank) Illustrator file.
    To use this file with other Illustrator projects choose Window > Swatch Library > Other Libraries and navigate to the saved Illustrator file (Desktop).
    At this point another swatches panel is opened on the screen.
    Drag the desired swatches from this new  panel to the document one. Then close the new panel.
    I hope this help

  • I saved a word file onto my imac.  when i go to open file in documents with pages the file is grey and unable to open.  the workable files are highlighted in bold.  is there a way to open this file????

    i saved a word file onto my imac.  when i go to open file in documents with pages the file is grey and unable to open.  the workable files are highlighted in bold.  is there a way to open this file????

    THis is safe for Mac's? Sorry, I have just never heard of this site before.
    And there are literally tens of thousands of sites of which I've not heard, too. Not this one.
    It's legit. There are lots of links in Apple Support Communities to the LibreOffice web site, as well as others that are legitimate open-source developers of options to buying MS Office, such as NeoOffice and OpenOffice. I have Open Office installed on one of my older Macs that can't run Office 2011 and it is rock-solid.
    I've been here too long to start posting bogus urls now.

  • When saving a File OS Is Creating Multiple Folders With The Same File Name

    Not sure what I changed but, now when I save a any file (ppt. word, Keynote,Pages e.g.,) to the desktop or any other location the OS will also create multiple file folders with the same file name as the file I'm saving. Inside the folders are what appears to be files locating the saved files. What can I do to fix this problem?
    I'm using the 10.7.2 version
    MacBook Pro

    Misio wrote:
    It looks like a finder bug. To replicate, I surf to any website, I right-click on a jpg image, select "Save Image As" and in the window that pops up I type in the filename "000.jpg", I select the folder Pictures, and click on Save.
    BTW, I don't know why, but the file was saved only as "000" without the file extension ".jpg". Does anybody know why?
    the extension is simply hidden. go to the get info panel for the file and uncheck the option to hide the extension.
    Then I surf to another image, and again I save it as "000.jpg" and now it asks me if I want to replace the existing filename, although the existing one is "000" and I try to save as "000.jpg", so I say yes, and then magically the file is saved with the full filename including the extension "000.jpg"
    When I did it a couple of times, always saving image as "000.jpg" from various sources, I ended up with two distinct files named "000" and both in the same folder Pictures.
    Please advise.
    it sounds to me like you saved one file as 000.jpg and the other and 000.jpg.jpg.
    check the info panels for the files for full names to verify if this is the case.

  • Saving a file in Vi creates same file but with ~ added [SOLVED]

    Hi,
    I'm not sure if I pressed a key combination, but when I save a file in Vi I get another file that has the same name as the original file but with the ~ character added to the end of the filename.  For example, if I edit foo.txt and save it, then the original will be saved, but I'll also get a new file named foo.txt~.  Does anyone know how to fix this?
    Thanks!
    -nterpol
    Last edited by nterpol (2008-11-09 12:30:59)

    I think that the default backup settings (in /etc/virc if you use the basic vi package) changed with the recent upgrade to Vim 7.2.25.
    For information on file backup setting combinations, see :help backup-table in Vim.
    Edit:
    fwojciec wrote:http://thehumblecoder.wordpress.com/200 … kup-files/
    That article advocates disabling the use of swap files (:set noswapfile); however, I wouldn't recommend it. Whereas backup files are designated with a trailing tilde (~), swap files have names ending with .swp. The latter should be removed automatically when Vim exits (unless it is exited abnormally, such as when the user closes a terminal emulator without first quitting an instance of Vim that is running inside it).
    Last edited by ssjlegendx (2008-11-10 04:13:24)

  • My daughter had completed a chart in pages. I saved it and then clicked on other chart types. Now I can't go back to the original chart she made even though I have not re-saved the file. How can I go back to her original chart with data?

    My daughter had completed a chart in pages. I saved it and then clicked on other chart types. Now I can't go back to the original chart she made even though I have not re-saved the file. How can I go back to her original chart with data?

    I don't get what you are saying.
    Is this all the same document?
    What version of Pages?
    Have you tried to revert to a previous version?
    Peter

Maybe you are looking for