Implementing Save dialog in jsp

Hi all,
I need a small help. I have one excel file and one link called download. When we press the "download " link it should prompt us to save and the file must be saved.
please help me how i can implement save dialog.
Any help is appreciated.
Thanking you in advance.
Regards,
Devi.

Take a look at this post: http://forum.java.sun.com/thread.jspa?threadID=5170452&messageID=9655276
( Remember to update the filestreams to buffered streams if you do use the sample )

Similar Messages

  • How to open a Save Dialog in JSP?

    Hi all, i need to export a CSV file. A button is provided to the user to choose where to save the file. My problem is how to open a 'Save As' dialog box in JSP?

    Hi all, i need to export a CSV file. A button is provided to the user to choose where to save the file. My problem is how to open a 'Save As' dialog box in JSP?

  • How to download files in jsp code {through save dialog}

    can you help me to download files in jsp code {through save dialog}
    i use the following code but it saves the jsp page instead of the downloaded file but with the name of the wanted file to be downloaded
    response.setHeader("Pragma", "public");
    response.setHeader("Cache-Control", "no-cache");
    *** download file
    if((trans !=null)&&(trans.equals("download")) )
    response.setContentType ("application/x-download");
    response.setHeader ("Content-Disposition","attachment;filename=\""+fileName+"\"");
    %>
    <script>
    window.location.href=<%=gallerypath+fileName%>';
    </script>
    <%
    trans="";
    //System.out.print("download : "+fileName );
    //***************************************

    Can you try below code, It should work...
    <%
    String myFileName = request.getParameter("fileName");
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + myFileName + "\"");
    String root = "D:/";
    InputStream in = null;
    ServletOutputStream outs = response.getOutputStream();
    try {
    in = new BufferedInputStream
    (new FileInputStream(root + myFileName));
    int ch;
    while ((ch = in.read()) != -1) {
    outs.print((char) ch);
    finally {
    if (in != null) in.close(); // very important
    outs.flush();
    outs.close();
    in.close();
    %>

  • Invoke SaveAs dialog using a JSP

    Hi all,
    Can anyone tell me how to invoke the SaveAs dialog window from a JSP so that the user can save a file?
    Thanks in advance,
    Graham

    <%@page contentType="application/octet-stream"%>
    <%@page pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
        <h1>JSP Page</h1>
    Somebody save me! I don't care how you do it, just save, save me!
        </body>
    </html>

  • Call Save Dialog [Save As] is not allowing me to Bookmark in Portal

    Hi All,
    I am facing some problems trying to implement BEx bookmarking into my Portal. To explain a little further about our setup, we have a master web template which is connected to approximately 80+ queries. Within that web template, we have a button which has the CALL SAVE Dialog Save_As which should, in theory, allow users to bookmark their queries via the Portal.
    Unfortunately, this is not working and when a user attempts to bookmark a query and save it via the Portal, the following blank screen is displayed with this URL: http://PORT NUMBER/irj/portalapps/com.sap.portal.navigation.helperservice/html/child.html.
    If anyone could offer any insight into this issue I'd be truly grateful - THANKS!
    Bim

    Hi,
    There might be a technical Rollup
    When you restart the Application Host Helper Service on Windows Server 2008, it might help.
    Or, if not, why don't you try to take an backup of the existing queries & perform a backup. I'm sure the error can be resolved.
    Thanks,
    Arun Bala G

  • Need help adding a default file name in a file chooser of save dialog type

    I need to create a file chooser with save dialog type, how can I add a highlighted default file name into the File Name textfield? As in Microsoft Word, when you want to save a document, a default file name Doc1.doc will appear in the File name text field of the file chooser even when you change to other directories.

    For JRE 1.4.0 you can use this fix:
    public class FileChooserFix implements PropertyChangeListener {
      private String fileName;
       * @see PropertyChangeListener
      public void propertyChange(PropertyChangeEvent ev) {
        JFileChooser chooser = (JFileChooser)ev.getSource();
        if (JFileChooser.FILES_ONLY == chooser.getFileSelectionMode()) {
          if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(ev.getPropertyName())) {
            File selectedFile = (File)ev.getNewValue();
            if (selectedFile != null) {
              // remember fileName of selected file
              fileName = selectedFile.getName();
          if (fileName != null &&
              JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(ev.getPropertyName())) {
            // reset selected file
            File directory = (File)ev.getNewValue();
            chooser.setSelectedFile(new File(directory, fileName));
       * Convenience method to create a fixed file chooser.
       * @return      fixed file chooser
      public static JFileChooser create() {
        JFileChooser chooser = new JFileChooser();
        chooser.addPropertyChangeListener(new FileChooserFix());
        return chooser;

  • Custom Save Dialog and Logic in Outlook 2013 Add in

    I'm creating an addin for outlook 2013. I've got it all setup and such but I'm not sure how to achieve my objective. My boss wants a button on a ribbon that is shown during compose, read, and similar methods and either opens a save dialog or just
    saves it automatically without the dialog. The catch is that I want to add custom actions for this special save button, where it will rename the file and save it in a specific folder. All based on the sender's domain and address, the date, whether there are
    attachments, and such. Either it will save the attachments as well or I could have a separate button to do the same with any attachments; archiving them and renaming them a specific way based on date, file type, sender, etc.
    How can I implement this? I assume it's in the method showMessage_Click. Which leads me to another question, what is the showMessage_Click even from? It is what causes my messagebox to pop up when you click the button, but assuming I want a save
    dialog or something else rather than a messagebox, do I still use showMessage_Click or is there another XXX_Click method to use for when clicking the button that would be more appropriate for my goals.
    Also is there a list somewhere showing all of these different event methods?
    Thanks for any help and guidance you can offer.

    Hello,
    It looks like you need to replace the standard SaveAs dialog with your own. To get this implemented you may repurpose the Save buttons on the ribbon, so each time the user clicks to save the item your custom dialog window is displayed. See Temporarily
    Repurpose Commands on the Office Fluent Ribbon for more information. 
    If you need to implement this as a separate feature - just add custom controls to the Ribbon UI (aka Fluent UI). See Walkthrough: Creating a Custom Tab
    by Using the Ribbon Designer to get started quickly. 

  • SAVE DIALOG!!!!

    why does a save dialog always point to the jsp as default?how can i specify a different file, to save......
    Are there any restrictions as to where my file has to exist on the server?
    If i say
    response.setContentType("application/zip");
    response.setHeader("Content-Disposition","filename=charlie.zip");
    It looks for a zip file so how do i use it to look for an excel file, i don't have any servlet will it work?
    Any suggestions or help would be appreciated and thanks in advance......

    Hi,
    You can include these lines in your code to get Excel file.
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition","attachment; filename=" + "example.xls" );
    Hope this helps you.
    Thanks,
    Senthil_Slash

  • Default buttons on save dialog

    Hi all,
    I am working with one application and it has a save dialog box which is implemented using JFileChooser. On the Save dialog box, I see four buttons on the right. First of them is to go up a level, second is to go to home, third is for a new folder and the forth is to display file details. The first three are working fine, but the fourth one does not give any results. It I take my cursor on the button, the tool tip says "details", but when I click on that button, nothing happens. Do I need to do something special in my code to activate "details"??
    Any help would be greatly appreaciated.
    Thanks,
    Namrata

    I posted the same question more than one year ago. No answer yet.

  • Download file in struts - File save dialog not showing up

    Hi,
    The issue i have is - the file save dialog box which should be displayed on file download is not showing up.
    I have a DAO being called from the Action form SaveDocumentAction which extends DispatchAction and has a download(mapping, request, response,..) method. Below are relevant portions of my code.
    public void showDocument(DocumentTO Doc, HttpServletResponse response){
    //get filename etc
    response.setContentType("application/x-download");
    response.setHeader("Content-Disposition", "attachment; filename=myFile.txt");
    OutputStream out = response.getOutputStream();
    //code for writing from input file to out
    I shld be getting a File Save dialog after response.setHeader(), but I am not. Can anyone tell me where I am going wrong. I have printed SOPs and all print fine, even the file writing part.

    Put this code into a servlet rather than a JSP.
    JSP are for returning text based HTML pages. It adds extra carriage returns into the response that will corrupt the file, and prevent the dialog showing up.
    This code is much better off being in a servlet
    If you are using a FileInputStream, you should be using a ServletOutputStream rather than the JSP writer: response.getOutputStream()
    When dealing with file input in a JSP/Servlet you should use the methods of ServletContext. getRealPath() turns a website relative file into a real location on disk. getResourceAsStream() opens the file for you. getResourceAsStream() is more reliable as it will work even if the web app is deployed in a packed WAR.
    Cheers,
    evnafets

  • File Save dialog box not showing correct file name while saving file

    hi
    Currently, after the Submit button is hit, the File Save dialog box is displayed. If the user saves the file and then opens it then the output appears correct however if the user chooses to open the file without saving on the local machine then the correct viewer is not used to display the file. The name of the file is defaulted as qotSCopPrint.jsp and the default file viewer for jsp files is chosen to view the file. The format of the file is obviously not text (it is either pdf or rtf) so the output shows binary characters.

    data : v_repid like sy-repid.
    parameters : p_file like rlgrap-filename.
    initialization.
    v_repid = sy-repid.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL FUNCTION 'F4_FILENAME'
           EXPORTING
                program_name  = v_repid
                dynpro_number = syst-dynnr
                field_name    = 'P_FILE'
           IMPORTING
                file_name     = p_file.
    Message was edited by:
            Chandrasekhar Jagarlamudi

  • Save a frame using saveAs dialog box.

    Hi,
    I am implementing an application wherein I am displaying certain error messages in a frame. On the lower frame I have have the buttons to print the contents of the upper frame. But I want to include the option to save the contents of the Upper Frame as a text file in the system directory using a SaveAs Dialog box. Can anyone please suggest how this can be done?
    I was using *{document.execCommand("saveAs")}* command to save the contents when the whole thing was done in a single html template but as I had to divide it in two different frames the above command is forming a .txt file but without any of the contents present. Any modification to be done to the above command such that the contents of the Upper frame get stored as .txt file would be very helpful too.??
    Thanks in advance.

    Is this a Java question? Note that JavaScript is not Java.
    db

  • Check if file downloaded successfully , through Open Save dialog box

    hi,
    In the jsp I have a download link through which user can download a file which is located on the server . I have achieved this by setting the response type in servlet as follows => response.setHeader("Content-Disposition", "attachment; filename=" + fileName); .When the jsp page loads the user is shown a Open Save dialog box for downloading the file. The user can download the file or cancel the operation.
    But now I need to track if the user has downloaded the file successfully on his m/c , depending on which a flag will be updated in the database . I am not able to track this event . Pls help how I can check if the file has been downloaded successfully and do further processing.

    This is fully dependent on the client side. You can never rely on that.
    In most cases you could check if any byte of the file is written to the outputstream and/or no IOException is been thrown, but some webbrowsers (such as Firefox) will download the file immediately while the client still need to choose 'save' or 'cancel'. Only when the client chooses 'cancel' the download will be aborted and the file will be deleted. But if the file is small and/or the network is fast, then the file download might be already completed at that time.
    Again, you can never rely on what happens at the client side.

  • JFileChooser as save dialog clears text field on change directory

    I am trying to implement a basic save dialog using JFileChooser, which initiates with an initial file name, "untitled.txt". However, as soon as the directory is changed by the user, the text field is cleared. I want to ensure that whatever is in the text field when the user changes directories (i.e., untitled.txt may have been changed to something else by the user) stays visible throughout any kind of user navigation. I've tried all sorts of things, but nothing seems to work.
    Thanks for your help.

    Yes, it very well could be an OS/JDK issue. I'm using jdk 1.5 on Mac OS X (Tiger). Apparently, FileNameExtensionFilter is a jdk 1.6 implementation, because it doesn't work for me.
    Here's my code:
    JFileChooser fc = new JFileChooser();
    String output = outputTextArea.getText();
            String selectedFile = "untitled.txt";
            File file = new File(selectedFile);
            fc.setDialogTitle("Save");
            fc.setMultiSelectionEnabled(false);
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fc.setSelectedFile(file);
            setFileName(file.getName());
            int result = fc.showSaveDialog(this);
            if (result == JFileChooser.CANCEL_OPTION) {
                return;
            } else if (result == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                if (file.exists()) {
                    int response = JOptionPane.showConfirmDialog(null,
                            "Overwrite existing file?","Confirm Overwrite",
                            JOptionPane.OK_CANCEL_OPTION,
                            JOptionPane.QUESTION_MESSAGE);
                    if (response == JOptionPane.CANCEL_OPTION) return;
                if (!writeFile(file, output)) {
                    setErrorMessage(ERROR5_1); //Just a custom error message and display.
                    showErrorMessage();
                    return;
            }Is there a workaround if this is an OS or JDK issue?
    Thanks again for your help.

  • Custom Personalization Dialog for JSP Dynpage

    Hi,
    i have a JSP Dynpage Component with the bean. i want to allow the user to personalize the iView when they click the "Personalize" in the iView Tray. So i have implemented doEdit() in the JSP Dynpage class and setting a JSP in the doEdit(). But in the portal the iView is not bringing any custom personalization JSP when i click "Personalize" in the iVIew Tray Drop Down Menu.
    doEdit() method wont work for JSP Dynpage ? is it only for Abs Portal Component ?
    Thanks,
    Saravanan

    Hi Saravanan,
    Hi Saravanan,
    JSPDynPage is more elaborate version of the DynPag. It creates a JSP file and, optionally, a Bean class.
    This means that the doProcessBeforeOutput methods are slightly different and there is an additional JSP file and an optional Bean class file. There are obviously other differences (such as the differences in the portalapp.xml file).
    Just check with a sample Portalapp.xml file:
    Ensure all the entries are made.
    <application>
      <application-config>
        <property name="releasable" value="true"/>
      </application-config>
      <components>
        <component name="BeginEPDevelopment">
          <component-config>
            <property name="ClassName" value="com.yourcompany.BeginEPDevelopment"/>
          </component-config>
          <component-profile>
            <property name="diplayHistory" value="10">
              <property name="plainDescription" value="BlogEntries"/>
              <property name="personalization" value="dialog"/>
            </property>
            <property name="diplayStyle" value="list">
              <property name="type" value="select[list,entries]"/>
              <property name="personalization" value="dialog"/>
            </property>
          </component-profile>
        </component>
      </components>
      <services>
        <service name="BeginEPDevelopmentService">
          <service-config>
            <property name="startup" value="true"/>
            <property name="className" value="com.yourcompany.BeginEPDevelopmentService"/>
          </service-config>
          <service-profile>
            <property name="BlogComments" value="Display"/>
          </service-profile>
        </service>
      </services>
    </application>
    Hope it helps you.
    Regards,
    Ponneswari.

Maybe you are looking for