You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Joshua Jackson <jo...@gmail.com> on 2007/12/12 05:47:40 UTC

How to get resources from our web-app context ?

Dear all,

In my wicket apps, I have a use case to read a file that is located in
my web-app context. How do I do this in wicket?

Thanks in advance,

-- 
I'm a coder not a drag-n-dropper

Blog: http://joshuajava.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to get resources from our web-app context ?

Posted by Joshua Jackson <jo...@gmail.com>.
Thank you so much.

That was helpful. It works now :)

On 12/12/07, wicket user <di...@googlemail.com> wrote:
> this is what spec says
> getRealPath
>
> public java.lang.String *getRealPath*(java.lang.String path)
>
> Returns a String containing the real path for a given virtual path. For
> example, the path "/index.html" returns the absolute file path on the
> server's filesystem would be served by a request for "
> http://host/contextPath/index.html", where contextPath is the context path
> of this ServletContext..
>
> The real path returned will be in a form appropriate to the computer and
> operating system on which the servlet container is running, including the
> proper path separators. This method returns null if the servlet container
> cannot translate the virtual path to a real path for any reason (such as
> when the content is being made available from a .war archive).
> *Parameters:*path - a String specifying a virtual path*Returns:*a
> Stringspecifying the real path, or null if the translation cannot be
> performedSo
> if the file is with in your context, then you should be able to get it using
> the getRealPath(), if it's out side then you will have to specify the
> absolute path.

-- 
I'm a coder not a drag-n-dropper

Blog: http://joshuajava.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to get resources from our web-app context ?

Posted by wicket user <di...@googlemail.com>.
this is what spec says
getRealPath

public java.lang.String *getRealPath*(java.lang.String path)

Returns a String containing the real path for a given virtual path. For
example, the path "/index.html" returns the absolute file path on the
server's filesystem would be served by a request for "
http://host/contextPath/index.html", where contextPath is the context path
of this ServletContext..

The real path returned will be in a form appropriate to the computer and
operating system on which the servlet container is running, including the
proper path separators. This method returns null if the servlet container
cannot translate the virtual path to a real path for any reason (such as
when the content is being made available from a .war archive).
*Parameters:*path - a String specifying a virtual path*Returns:*a
Stringspecifying the real path, or null if the translation cannot be
performedSo
if the file is with in your context, then you should be able to get it using
the getRealPath(), if it's out side then you will have to specify the
absolute path.

I am not sure if there is any other way around

regards
dipu


On Dec 12, 2007 9:36 AM, Joshua Jackson <jo...@gmail.com> wrote:

> Yeah,
>
> It doesn't work with ServletContext.getRealPath("").
>
> I have a template.vm that is located under my web-app context and I
> want to read that file from wicket. But since Servlet is not exposed
> direclty, I don't know how to do this in wicket.
>
> Thanks in advance,
>
> On 12/12/07, wicket user <di...@googlemail.com> wrote:
> > can't use ServletContext.getRealPath("") to get the actual file path and
> > read the file as you read normally.
> >
> > getServletContext() method will return the ServletContext.
> >
> > Or are you looking for something different ?
> >
> > regards
> > dipu
> --
> I'm a coder not a drag-n-dropper
>
> Blog: http://joshuajava.wordpress.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to get resources from our web-app context ?

Posted by Joshua Jackson <jo...@gmail.com>.
Yeah,

It doesn't work with ServletContext.getRealPath("").

I have a template.vm that is located under my web-app context and I
want to read that file from wicket. But since Servlet is not exposed
direclty, I don't know how to do this in wicket.

Thanks in advance,

On 12/12/07, wicket user <di...@googlemail.com> wrote:
> can't use ServletContext.getRealPath("") to get the actual file path and
> read the file as you read normally.
>
> getServletContext() method will return the ServletContext.
>
> Or are you looking for something different ?
>
> regards
> dipu
-- 
I'm a coder not a drag-n-dropper

Blog: http://joshuajava.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to get resources from our web-app context ?

Posted by wicket user <di...@googlemail.com>.
can't use ServletContext.getRealPath("") to get the actual file path and
read the file as you read normally.

getServletContext() method will return the ServletContext.

Or are you looking for something different ?

regards
dipu

On Dec 12, 2007 4:47 AM, Joshua Jackson <jo...@gmail.com> wrote:

> Dear all,
>
> In my wicket apps, I have a use case to read a file that is located in
> my web-app context. How do I do this in wicket?
>
> Thanks in advance,
>
> --
> I'm a coder not a drag-n-dropper
>
> Blog: http://joshuajava.wordpress.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to get resources from our web-app context ?

Posted by Newgro <pe...@gmx.ch>.
Hi Joshua,

In a page
ServletContext context = ((WebApplication)
getApplication()).getServletContext();
File reportFile = new File(context.getRealPath("/reports/myReport.jasper"));

under webapp put a reports folder

You can use every file / image / whatever

HTH
Per

-- 
View this message in context: http://www.nabble.com/How-to-get-resources-from-our-web-app-context---tp14289017p14291554.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org