Hello Luca
Here are the instructions for writing application/applet

Write a java application or applet that downloads a file from across the network. Due to security considerations, applets may only download files on the server from which they were downloaded. To download a file, you must construct the URL location as an instance of the URL class. With the URL class in hand, you can invoke the openConnection() method to retrieve an instance of the URLConnection class. From here there are two options:

  • Get an input stream from the connection using the getInputStream() method of URLConnection and use it to retrieve information over the connection. Note: it is also possible to send information over an output stream with the counterpart method getOutputStream().

  • Write a custom ContentHandler that manipulates the data for a file of a certain type. To do this you must first implement the ContentHandlerFactory interface. The createContentHandler(String mimetype) method returns a subclass of ContentHandler that handles the data for a file of type mimetype. For example for content type "text/plain" the call to your ContentHandlerFactory would return your special ContentHandler, PlainTextHandler. The next step, then, is to implement PlainTextHandler by defining the abstract method getContent(URLConnection). The PlainTextHandler will then get an InputStream from the URLConnection, manipulate the data and return an Object representing the data. In the demo, the ContentHandler sandwiches the data between a header and trailer and returns the new String. To make use of the ContentHandler, do the following:
         url_connection.setContentHandlerFactory(new your_conyentHandlerFactory());
            Object data url_connection.getContent();
    
    In getContent() the url_connection asks the factory for a ContentHandler based on the content type. If a something other than null returns, then the URLConnection inokes the getContent() method of the ContentHandler. Otherwise, the URLConnection uses the default handler for the content type. Note: This doesn't work in applets, a SecurityException is invariably thrown.


Once you have this FileDownload.class compiled
assuming you have CShell
try this script:

#!/usr/bin/csh -f

# Let the java interpreter know where to look for the thread demo.
# The java interpreter looks for class files in the directories listed
# in the environment variable CLASSPATH.
#assume /project/adaptive/classes/cs544/assignments/download is the direcory where FileDownload.class was compiled
setenv CLASSPATH ${CLASSPATH}:/project/adaptive/classes/cs544/assignments/download

# Run the DownLoad demo.
# This demo is still under development, the file it downloads is hardcoded into
# the source. It downloads a file from the cs webserver and pops up a text viewing
# window. A content handler prepends a header and appends a trailer to the body
# of the document.
#ASSUME java JAVA_HOME/bin is /pkg/java/bin
/pkg/java/bin/java FileDownload

Migliore,
Martin Gainty

______________________________________________

Disclaimer and confidentiality note

Everything in this e-mail and any attachments relating to the official business of Laconia Data Systems (LDS) is proprietary to the company. It is confidential, legally privileged and protected by law. LDS does not own and endorse any other content. Views and opinions are those of the sender unless clearly stated as being that of LDS.

The person addressed in the e-mail is the sole authorised recipient. Please notify the sender immediately if it has unintentionally reached you and do not read, disclose or use the content in any way.

LDS can not assure that the integrity of this communication has been maintained nor that it is free of errors, virus, interception or interference.

             _____________GMT-5___________________

 

>From: Luca Ventura <[EMAIL PROTECTED]>
>Reply-To: A mailing list about Java Server Pages specification and reference <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: R: Download a file using HttpUrlconnection class (??)
>Date: Tue, 10 Sep 2002 22:04:11 +0200
>MIME-Version: 1.0
>Received: from mc3-f33.law16.hotmail.com ([65.54.236.168]) by mc3-s10.law16.hotmail.com with Microsoft SMTPSVC(5.0.2195.5600); Tue, 10 Sep 2002 13:04:04 -0700
>Received: from swjscmail2.java.sun.com ([192.18.99.108]) by mc3-f33.law16.hotmail.com with Microsoft SMTPSVC(5.0.2195.5600); Tue, 10 Sep 2002 13:04:03 -0700
>Received: from swjscmail1 (swjscmail1.Sun.COM [192.18.99.107])by swjscmail2.java.sun.com (Postfix) with ESMTPid 6D920230C4; Tue, 10 Sep 2002 14:01:06 -0600 (MDT)
>Received: from JAVA.SUN.COM by JAVA.SUN.COM (LISTSERV-TCP/IP release 1.8d) with spool id 2660499 for [EMAIL PROTECTED]; Tue, 10 Sep 2002 13:59:12 -0600
>Received: from mail.tiscali.it (mail-2.tiscali.it [195.130.225.148]) by swjscmail1.java.sun.com (Postfix) with ESMTP id 45D6A4828 for <[EMAIL PROTECTED]>; Tue, 10 Sep 2002 13:59:12 -0600 (MDT)
>Received: from aquarius (62.11.39.16) by mail.tiscali.it (6.5.026) id 3D6E3431004C16BB; Tue, 10 Sep 2002 22:03:30 +0200
>Delivered-To: [EMAIL PROTECTED]
>X-Priority: 3 (Normal)
>X-MSMail-Priority: Normal
>X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>Importance: Normal
>Message-ID: <[EMAIL PROTECTED]>
>Sender: A mailing list about Java Server Pages specification and reference <[EMAIL PROTECTED]>
>Comments: cc: [EMAIL PROTECTED]
>In-Reply-To: <[EMAIL PROTECTED]>
>Return-Path: [EMAIL PROTECTED]
>X-OriginalArrivalTime: 10 Sep 2002 20:04:03.0332 (UTC) FILETIME=[35DF2440:01C25905]
>
>Hello!
>
>Thanks for your hint! Anyway it would be better to have a code example...do
>you have it?
>
>Regards,
>
>
> Luca
> -----Messaggio originale-----
> Da: A mailing list about Java Server Pages specification and reference
>[mailto:[EMAIL PROTECTED]]Per conto di Martin Gainty
> Inviato: marted́ 10 settembre 2002 17.15
> A: [EMAIL PROTECTED]
> Oggetto: Re: Download a file using HttpUrlconnection class (??)
>
>
> Luca:
>
> try
> http://www.cs.wustl.edu/~schmidt/cs544/download.html
>
>
>
> avere piacere!
>
> -Martin
>
>
> >From: Luca Ventura
> >Reply-To: A mailing list about Java Server Pages specification and
>reference
> >To: [EMAIL PROTECTED]
> >Subject: Download a file using HttpUrlconnection class (??)
> >Date: Tue, 10 Sep 2002 13:37:24 +0200
> >MIME-Version: 1.0
> >Received: from mc3-f3.law16.hotmail.com ([65.54.236.138]) by
>mc3-s1.law16.hotmail.com with Microsoft SMTPSVC(5.0.2195.5600); Tue, 10 Sep
>2002 04:38:22 -0700
> >Received: from swjscmail2.java.sun.com ([192.18.99.108]) by
>mc3-f3.law16.hotmail.com with Microsoft SMTPSVC(5.0.2195.5600); Tue, 10 Sep
>2002 04:37:56 -0700
> >Received: from swjscmail1 (swjscmail1.Sun.COM [192.18.99.107])by
>swjscmail2.java.sun.com (Postfix) with ESMTPid 288B422CF0; Tue, 10 Sep 2002
>05:35:07 -0600 (MDT)
> >Received: from JAVA.SUN.COM by JAVA.SUN.COM (LISTSERV-TCP/IP release
>1.8d) with spool id 2632683 for [EMAIL PROTECTED]; Tue, 10 Sep 2002
>05:33:15 -0600
> >Received: from hal-7.inet.it (hal-7.inet.it [213.92.5.33]) by
>swjscmail1.java.sun.com (Postfix) with ESMTP id 6F222480D for ; Tue, 10 Sep
>2002 05:33:14 -0600 (MDT)
> >Received: from [::ffff:194.185.222.237] by hal-7.inet.it via
>I-SMTP-4.2.1-420 id 073+Wrde1cYSJ; Tue, 10 Sep 13:37:30 2002 +0200
> >Delivered-To: [EMAIL PROTECTED]
> >X-Priority: 3 (Normal)
> >X-MSMail-Priority: Normal
> >X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
> >Importance: Normal
> >Message-ID:
> >Sender: A mailing list about Java Server Pages specification and
>reference
> >Return-Path: [EMAIL PROTECTED]
> >X-OriginalArrivalTime: 10 Sep 2002 11:37:57.0023 (UTC)
>FILETIME=[82241AF0:01C258BE]
> >
> >Hello everybody!
> >
> >I would like my servlet or jsp-page to download a file from an http or
>https
> >url
> >(for example: http://www.domain.com/filetodownload.pdf). So I suppose
> >I must use HttpUrlconnection or HttpsUrlconnection classes. Am I right?
> >How can I do all this in my servlet? Then I would like to send the file
>just
> >read to the
> >user that connects to my servlet: is it possible to send it
> >"on the fly" without saving it on disk before? In fact I would like to
>send
> >it
> >to the user while the servlet is reading (downloading) it.
> >Which type of java variables (String or what??? )must I use to store
> >"temporarly" the data of the file
> >I am reading and downloading?
> >
> >Can you give me a code example please?
> >
> >Thanks a lot in advance!
> >
> > Luca
> >
>
> >===========================================================================
> >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://archives.java.sun.com/jsp-interest.html
> > http://java.sun.com/products/jsp/faq.html
> > http://www.esperanto.org.nz/jsp/jspfaq.jsp
> > http://www.jguru.com/faq/index.jsp
> > http://www.jspinsider.com
>
>
>----------------------------------------------------------------------------
>--
> Chat with friends online, try MSN Messenger: Click Here
>
>===========================================================================
>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://archives.java.sun.com/jsp-interest.html
>http://java.sun.com/products/jsp/faq.html
>http://www.esperanto.org.nz/jsp/jspfaq.jsp
>http://www.jguru.com/faq/index.jsp http://www.jspinsider.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://archives.java.sun.com/jsp-interest.html
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.jsp
> http://www.jguru.com/faq/index.jsp
> http://www.jspinsider.com


MSN Photos is the easiest way to share and print your photos: Click Here
=========================================================================== 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://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com

Reply via email to