Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 93096 invoked by uid 500); 12 Oct 2001 15:19:50 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: tomcat-user@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 93027 invoked from network); 12 Oct 2001 15:19:49 -0000 Message-ID: <3BC7081E.B79660B3@cybershop.ca> Date: Fri, 12 Oct 2001 11:11:27 -0400 From: Bo Xu X-Mailer: Mozilla 4.7 [en] (WinNT; I) X-Accept-Language: en MIME-Version: 1.0 To: tomcat-user@jakarta.apache.org Subject: Re: ServletContext.getResource() : is it read-only or read-write ? References: <00a801c1532a$ecee8130$0a14a8c0@terre> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-MDaemon-Deliver-To: tomcat-user@jakarta.apache.org X-Return-Path: bo@cybershop.ca X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N chris brown wrote: > Hi, > > I've been looking at using getResourcePaths() and getResource() as a way of > simplifying deployment and increasing portability. > > "getResource()" returns a java.net.URL, from which I imagine you're supposed > obtain a subclass of URLConnection. Instances of URLConnection have > "getInputStream()" and "getOutputStream()" methods... are both of these > methods supported in Tomcat 4? As in, can resources be read/write, or just > read-only? > > Furthermore, what kind of InputStream (and OutputStream) should I expect (or > use) with such URLConnections? > > Thanks, > -Chris I am not sure, I just guess perhaps it will dependent on different Servlet container, the following is from: http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.0/ jakarta-servletapi-4.zip ... javax.servlet Interface ServletContext ... getResource public java.net.URL getResource(java.lang.String path) throws java.net.MalformedURLException Returns a URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root. This method allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a .war file. The servlet container must implement the URL handlers and URLConnection objects that are necessary to access the resource. This method returns null if no resource is mapped to the pathname. Some containers may allow writing to the URL returned by this method using the methods of the URL class. The resource content is returned directly, so be aware that requesting a .jsp page returns the JSP source code. Use a RequestDispatcher instead to include results of an execution. This method has a different purpose than java.lang.Class.getResource, which looks up resources based on a class loader. This method does not use class loaders. Parameters: path - a String specifying the path to the resource Returns: the resource located at the named path, or null if there is no resource at that path Throws: java.net.MalformedURLException - if the pathname is not given in the correct form ... BTW, could anybody tell me: in TC4.0, which class "implements" the interface "javax.servlet.ServletContext"? because I want to find the overrided code of "getResource"? Thanks in advance! :-) Bo Oct.12, 2001