Hey Roger,
Sorry, unfortunately it doesnt work that way.
When you get a resource for a page, it gives you the source of that page,
not the actual results of it.
>From servlet 2.3 specs:
"These methods are not used to obtain dynamic content. For example,
in a
container supporting the JavaServer PagesTM specification1, a method
call of the
form getResource("/index.jsp") would return the JSP source code and
not the
processed output. See Chapter SRV.8, "Dispatching Requests" for more
information about accessing dynamic content."
I have used in my code:
URL url = getServletContext().getResource("/flow.xml");
URLConnection conn = (URLConnection) url.openConnection();
InputStream in = conn.getInputStream();
This, however, reads the actual source of the resource.
To actually get the dynmaic content of it, you might consider not using
getResource and simply using the net package.
You might look at sample code for Applet/Servlet communication to find out
more.
http://java.sun.com/docs/books/tutorial/networking/urls/index.html
Also, depending on what you need to do, it might be sufficient to use the
include method of the requestDispatcher.
-Tim
-----Original Message-----
From: Varley, Roger [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 20, 2002 10:40 AM
To: [EMAIL PROTECTED]
Subject: Re: Your Message Sent on Tue, 19 Mar 2002 15:35:33 -0000
>
>
> You can only go back to the root of your project when using
> getResource
>
> For the servlet 2.3 specs:
>
> "The getResource and getResourceAsStream methods take
> a String with
> a
> leading "/" as argument which gives the path of the resource
> relative to the root of
> the context. This hierarchy of documents may exist in
> the server's
> file system, in a
> web application archive file, on a remote server, or
> at some other
> location."
>
> As you can see beginning with the / is a requirement.
>
> for mine, i use getServletContext().getResource("/flow.xml");
> This refers to the /flow.xml in my root directory.
> If your Register1.asp is not in the root directory or its
> subfolders then
> you need to move it.
Hi,
Thanks for your response. I've tried that and moved the register1.asp file.
The code now looks like;
ServletContext sc = config.getServletContext();
url = sc.getResource("/register1.asp");
System.out.println(url.toString());
I must be missing something obvious though because now the problem is that
getResource() is returning a file:// url not an Http url so when I try to
open the connection, the servlet crunches again. The system prints the
content of the URL as file:e:\tomcat\webapps\Application\register1.asp. I
need an HTTP connection.
Regards
Roger
************************************************************************
Information in this message is confidential and may be privileged. It is
for the exclusive use of the intended recipient(s). If you are not the
intended recipient(s) please notify the sender and delete the message
immediately. Unauthorised disclosure, distribution and copying of this
email is strictly prohibited. The opinions expressed within this message
are those of the individual author. Whilst Brake Bros takes reasonable
steps to scan this email it does not accept liability for any virus that may
be contained in it.
Bros Foodservice Limited, Enterprise House, Eureka Business Park, Ashford,
Kent TN25 4AG.
Registered in England and Wales number 706764.
Telephone 01233 206000 Fax 01233 206006.
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html