Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 53839 invoked from network); 29 Apr 2008 21:03:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Apr 2008 21:03:18 -0000 Received: (qmail 64770 invoked by uid 500); 29 Apr 2008 21:03:06 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 64748 invoked by uid 500); 29 Apr 2008 21:03:06 -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 64737 invoked by uid 99); 29 Apr 2008 21:03:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Apr 2008 14:03:05 -0700 X-ASF-Spam-Status: No, hits=4.5 required=10.0 tests=DNS_FROM_RFC_DSN,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [63.208.79.199] (HELO mail.jmlafferty.com) (63.208.79.199) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Apr 2008 21:02:18 +0000 Received: from lightning.linksys [98.210.13.60] by mail.jmlafferty.com with ESMTP (SMTPD32-7.07) id ACE711A00CA; Tue, 29 Apr 2008 16:02:31 -0500 Message-Id: <67B870DE-6244-4FEA-A89A-25261EC15F35@jmlafferty.com> From: David Fisher To: "Tomcat Users List" In-Reply-To: <661958.58601.qm@web25008.mail.ukl.yahoo.com> Content-Type: multipart/alternative; boundary=Apple-Mail-1628--732491079 Mime-Version: 1.0 (Apple Message framework v919.2) Subject: Re: access files from jsp Date: Tue, 29 Apr 2008 16:02:22 -0500 References: <661958.58601.qm@web25008.mail.ukl.yahoo.com> X-Mailer: Apple Mail (2.919.2) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-1628--732491079 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Hi Henry, > > most of these files are PDF, XLS and not only TXT > format. > You are meaning that with a JSP definitvly one can > reads only TXT files? When I had the trouble I was referred to the JSP spec and it is meant =20= for serving marked up Text formats. Encoding translations can happen =20 with JSP. With JSP it is easy to insert whitespace which will damage a =20= PDF or XLS file. So, you want a servlet. Servlets send only want you want to send. You can mount your remote system as a disk on your web server system =20 and then use pathnames as the "url" in my sample. We've done this =20 since Tomcat 3.0.3. Pretty simple. It is up to you if you need to obfuscate your file pathnames. Glad to help. Regards, Dave > > > i understood with help of > --- David Fisher schrieb: > >> Henry doesn't say if these are text files or binary >> files. >> >> If these are binary files like PDF, PPT and XLS >> files then a servlet >> will be needed - not a jsp. >> >> We use variations like the following in both Tomcat >> 4.1.31 and Tomcat >> 5.5.26 >> >> public class OpenFileServlet extends HttpServlet{ >> >> public void doGet (HttpServletRequest request, >> >> HttpServletResponse response) throws >> ServletException, IOException { >> >> // You probably want to look up the url - >> which is really a >> path. >> String url =3D request.getParameter("url"); >> if(url =3D=3D null) return; >> >> // You'll know your mime types for your >> content. >> String ext =3D request.getParameter("ext"); >> String content_type; >> >> if (".ppt".equals(ext)) {content_type =3D >> "application/vnd.ms- >> powerpoint"; } >> else if (".xls".equals(ext)) {content_type >> =3D "application/ >> vnd.ms-excel"; } >> else {content_type =3D "application/pdf";} >> >> // we don't like to inline Office >> documents. >> boolean is_inline =3D >> "application/pdf".equals(content_type); >> >> File f =3D new File(url); >> >> if ( f.exists() && f.length() > 0) { >> response.setContentType( content_type); >> // The following works way better in >> Windows IE than ext=3D >> >> response.setHeader("Content-disposition", >> (is_inline?"inline":"attachment")+";filename=3D" + >> f.getName()); >> int lng =3D (int)f.length(); >> response.setContentLength( lng ); >> FileInputStream fis =3D new >> FileInputStream(f); >> byte[] chunk =3D new byte[16184]; >> int count; >> while ((count =3D fis.read(chunk)) >=3D0 ) >> { >> >> response.getOutputStream().write(chunk,0,count); >> } >> fis.close(); >> } else { >> log("File not found: " + url); >> } >> } >> } >> >> >> >> FYI - this approach really became necessary about >> when 4.1.29 came out >> - at that time Tomcat got pretty strict with >> non-Text being served via >> JSP. All of our PDF and PPT content broke in Windows >> IE. And we had to >> back out a whole release. >> >> Regards, >> Dave >> >> On Apr 29, 2008, at 1:39 PM, David Smith wrote: >> >>> So... the "remote file" is available to the local >> system on a >>> network drive. That's a fun one. There are a >> couple of different >>> ways to do this. >>> >>> 1. Using Windows fileshares >>> >>> Let me preface this by saying *I've* never done >> this. The few times >>> I've had a tomcat server on a Windows machine, it >> only ever accessed >>> local files. There are people on the list with way >> more experience >>> than I have. >>> >>> As I understand it, as long as tomcat is running >> under a user >>> account that has privileges to read the remote >> file, you could use a >>> UNC path with java standard file access classes >> and methods to read >>> the file. The mapped drive letter wouldn't work >> unless tomcat was >>> only running while you are logged in. In a jsp, >> this could be done >>> with a scriptlet: >>> >>> >>> >>> try { >>> FileInputStream remoteFileReader =3D new >> FileInputStream( "\\\ >>> \remoteServer\\archive\\files\\myFile.txt" ) ; >>> // do something with the file >>> } catch ( Exception e ) { >>> // do something if the access fails >>> } finally { >>> try { >>> remoteFileReader.close() ; >>> } catch ( Exception e ) {} >>> } >>> >>> >>> It should be mentioned the system account most >> services run under by >>> default does not have any privilege to access >> remote files via UNC >>> path, so you'll have to customize your tomcat >> installation a >>> little. ... Or always be logged into the system >> and have it running >>> as you which isn't the most ideal method. >>> >>> 2. Using a webserver on the remote system >>> >>> This I have done and it's more platform >> independent. Your jsp can >>> request it from the remote server using standard >> taglibs: >>> >>> (note standard.jar and jstl.jar must be in your >> webapp's WEB-INF/lib >>> directory) >>> >>> >>> >>> > > url=3D"http://remoteSystem.dns.com/http/path/to/file.txt" >> >>> var=3D"fileContents" /> >>> >>> >>> >>> --David >>> >>> henry human wrote: >>>> Thanks David, >>>> I try to clarify my situation. >>>> I have a JSP running in local computer in tomcat. >> This >>>> JSP should read from a remote machine. The files >> are >>>> under d:\archive\files. These directory which >> provide >>>> a repository functionality could not be transfer >>>> somewhere else. The files =93must be=94 saved there. >> 1) Scennario one: >>>> The remote machine does not hava e >>>> webserver >>>> 2) Scenario two: a tomcat is running on remote >>>> computer >>>> My questions: >>>> 1) Do I need the webserver at all to access >> remotely >>>> the files? >>>> 2) Is it poosile to access the data on >> d:\archive=85 >>>> without to put them in a webserver directory or >> not? >>>> If no, do I need configuration for the webserver >> (f.i. >>>> tomcat)to allow access to the files from outside? >>>> >>>> --- David Smith schrieb: >>>> >>>> >>>>> Here's the picture you painted in the original >> email >>>>> and I based my answer on: >>>>> >> > =3D=3D=3D message truncated =3D=3D=3D > > > > __________________________________________________________ > Gesendet von Yahoo! Mail. > Mehr M=F6glichkeiten, in Kontakt zu bleiben. = http://de.overview.mail.yahoo.com > > --------------------------------------------------------------------- > 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 > > --Apple-Mail-1628--732491079--