Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 29135 invoked from network); 21 Feb 2007 14:46:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Feb 2007 14:46:13 -0000 Received: (qmail 15251 invoked by uid 500); 21 Feb 2007 14:46:01 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 15227 invoked by uid 500); 21 Feb 2007 14:46:00 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 15216 invoked by uid 99); 21 Feb 2007 14:46:00 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Feb 2007 06:46:00 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of awilli08@harris.com designates 137.237.90.89 as permitted sender) Received: from [137.237.90.89] (HELO mlbe2k2.cs.myharris.net) (137.237.90.89) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Feb 2007 06:45:49 -0800 Received: from mail pickup service by mlbe2k2.cs.myharris.net with Microsoft SMTPSVC; Wed, 21 Feb 2007 09:45:27 -0500 Received: from mlbe2k4.cs.myharris.net ([192.107.153.232]) by mlbe2k2.cs.myharris.net with Microsoft SMTPSVC(6.0.3790.1830); Wed, 21 Feb 2007 09:45:26 -0500 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: where to store user-generated files? Date: Wed, 21 Feb 2007 09:45:25 -0500 Message-ID: <6E19E11D3D7A5F4D937E5C2721FC310D04F3FA7E@mlbe2k4.cs.myharris.net> In-Reply-To: <806554940702210137p2392a90fraaa278a1ba4616fb@mail.gmail.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: where to store user-generated files? Thread-Index: AcdVm/JhFUi9mGNuRHOx+phnBiMJ6wAKgFGg From: "Williams, Allen" To: "Tomcat Users List" , X-OriginalArrivalTime: 21 Feb 2007 14:45:26.0531 (UTC) FILETIME=[ECA28D30:01C755C6] X-Virus-Checked: Checked by ClamAV on apache.org I'm new at this, so bear with me here for a moment... The servlet mapping seems to me to tell tomcat "anytime you have a request for a URI with .jpg extension, deliver the request to this servlet", but that doesn't give any information about where in the "real" file system said jpeg is stored, does it? So, when you call sc.getRealPath(), how does the servlet context know where to go? Doesn't there have to be a mapping or alias somewhere (server.xml, web.xml,...?) that resolves, or translates "ThisTypeofFileName.ext" into "/real/path/in/OS/ThatTypeOfFileName.oxt"? -----Original Message----- From: John Pedersen [mailto:john.pedersen@gmail.com]=20 Sent: Wednesday, February 21, 2007 4:37 AM To: Tomcat Users List Subject: Re: where to store user-generated files? Looks like roll your own then! A few thoughts on the matter - maybe someone could add to them? It should be easy to map requests for images to a servlet, which can then find the appropriate image file wherever it might be ( within or outside the server ). Like this in the web.xml file: servletName *.jpg ? But how is the image then added to the reponse? Another servlet ( behind the scenes - I am actually using the Spring framework ) is handling the request/response. Can the request/response be passed to the image-providing servlet for the images within a page to be written to the reponse in this kind of way: // This method is called by the servlet container to process a GET request. public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { // Get the absolute path of the image ServletContext sc =3D getServletContext(); String filename =3D sc.getRealPath("image.gif"); // Get the MIME type of the image String mimeType =3D sc.getMimeType(filename); if (mimeType =3D=3D null) { sc.log("Could not get MIME type of "+filename); =20 resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } // Set content type resp.setContentType(mimeType); // Set content size File file =3D new File(filename); resp.setContentLength((int)file.length()); // Open the file and output streams FileInputStream in =3D new FileInputStream(file); OutputStream out =3D resp.getOutputStream(); // Copy the contents of the file to the output stream byte[] buf =3D new byte[1024]; int count =3D 0; while ((count =3D in.read(buf)) >=3D 0) { out.write(buf, 0, count); } in.close(); out.close(); } ( from http://www.exampledepot.com/egs/javax.servlet/GetImage.html ) I'm off for a walk to mull it over - any suggestions while I am out and before I get to experimenting will be most welcome. Thanks, John --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org