hi there...

i am trying to download a certain file...

the problem...

The link id "download_file" in the application_map is the reference used in
the href statements in download_test.jsp, which in
turn calls the DownloadResponseHandler. (java class)

The problem is when the link is executed, the "Save As" dialog has the
default file name "download_file.html" displayed.

What I require is that this default file name be displayed as the FileName
value in the href, i.e. "myTextFile.txt".


following are the relevant code snippets...

Application_map:

==================================================================
application_map.xml

   <response id= "download_resp"
handler="com.sdrc._wae.ctrl.DownloadResponseHandler"/>

   <link id="download_file" response="download_resp"/>
==================================================================

JSP File:

<html>
<head>
<title>MWAS Download File</title>
</head>

<h1><font color="blue"> <b>Metaphase Download Files</b> </font></h1>
<body bgcolor="lightgrey">

<form name="download_form" method="post" action="download_items">
<table border=0 cellpadding=2 cellspacing=8>

<tr><td align=right>

<a
href="download_file?FileName=myTextFile.txt&EntityHandle=MTIObjectHandle-0001-1;ledsf6garh---rc4adminabd;EditText;rc4admin;;">myTextFile.txt</a>

<input type="button" value="Download"></td>

<tr><td align=right>
<a
href="download_file?FileName=myTextFile1.txt&EntityHandle=MTIObjectHandle-0001-1;leepA4harh---rc4adminabw;EditText;rc4admin;;">myTextFile1.txt</a>

<input type="button" value="Download"></td>

</table>
</form>
</body>


Java Class:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletOutputStream;

import java.util.Enumeration;
import java.io.IOException;

import com.sdrc.metaphase.enterprise.es.base.EnterpriseException;
import com.sdrc.metaphase.enterprise.es.base.EntityHandle;
import com.sdrc.metaphase.enterprise.es.base.Manager;
import com.sdrc.metaphase.enterprise.es.omf.vault.DownloadableFile;
import com.sdrc.metaphase.enterprise.es.omf.vault.Vaulter;
import com.sdrc.metaphase.enterprise.es.session.Session;
import com.sdrc.metaphase.enterprise.es.session.SessionAuthenticator;
import com.sdrc.metaphase.wae.CredentialsStore;

import com.sdrc.wae.ResponseHandlerSupport;
import com.sdrc.wae.RequestContext;
import com.sdrc.wae.util.RequestParamReader;

/**
* Download ResponseHandler .
* <p>
* <p>
*
*/
public class DownloadResponseHandler
extends ResponseHandlerSupport
{
   /**
    * Called to generate the HTTP response.
    * <p>
    * @param request    The HTTP request
    * @param response   The HTTP response to use for generating output.
    * @param context    Context for request, session, and Web application.
    */
   public void generateResponse(HttpServletRequest request,
         HttpServletResponse response,
         RequestContext context)
   {
      try
      {
         String             entity_handle_name = null;
         String             file_name          = null;
         RequestParamReader params    = context.getRequestParameters();

         if (params != null)
         {
            for (Enumeration e = params.getParameterNames() ;
e.hasMoreElements() ;)
            {
               String name = (String) e.nextElement();
               if (name.equals( "EntityHandle" ))
               {
                  entity_handle_name = params.getParameter(name);
               }
               else if (name.equals( "FileName" ))
               {
                  file_name = params.getParameter(name);
               }
            }
         }

         // ContentType forces the Save As dialog for all file types.
         response.setContentType("application/octet-stream");
         response.setLocale(context.getUserLocale());

         try
         {
            ServletOutputStream  pw            = response.getOutputStream();
            Manager              a_manager     = new
com.sdrc._metaphase.enterprise.es_evista.base.Manager();
            SessionAuthenticator authenticator =
a_manager.getSessionAuthenticator();
            Session              es_session    =
authenticator.establishSession(
CredentialsStore.getUserCredentials(context));
            Vaulter              vaulter_new   =
(Vaulter)a_manager.getProcessor("omf.vault.Vaulter", es_session);
            EntityHandle         entity_handle =
vaulter_new.getEntityHandleByName(entity_handle_name);
            DownloadableFile     downloadable  =
vaulter_new.constructDownloadable(entity_handle);
            vaulter_new.downloadToStream( downloadable, pw );
         }
         catch (EnterpriseException e)
         {
            System.out.println("Error 1: DownloadResponseHandler "+e);
            e.printStackTrace();
         }
      }
      catch (IOException e)
      {
         System.out.println("Error 2: DownloadResponseHandler");
         e.printStackTrace();
      }
   }
}



any ideas...

thanx in advance
abhi
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to