You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Henry Chen <he...@gmail.com> on 2005/05/05 17:08:56 UTC
Problem with ServletContext.getResource()
Hi,
I want to write to a file. I use the following method:
String contextPath =
cycle.getRequestContext().getRequest().getContextPath();
ServletContext context =
cycle.getRequestContext().getServlet().getServletContext();
String somefile = contextPath +"abc.zip";
String outFileName = context.getResource(somfile).getFile();
This return a null value for context.getResource(somfile). I tried
getRealPath(), it worked, but it was deprecated. Anybody knows what the
problem is here? Or there are some other better ways?
Many Thanks.
Henry
Re: Problem with ServletContext.getResource()
Posted by Kent Tong <ke...@cpttm.org.mo>.
Henry Chen <henry.chen04 <at> gmail.com> writes:
Try:
ServletContext context =
cycle.getRequestContext().getServlet().getServletContext();
String somefile = "/abc.zip";
//String outFileName = context.getResource(somfile).getFile();
String outFileName = context.getRealPath(somfile);
As you're trying to write to the file, you can't use getResource().
Instead, use getRealPath(). I don't know why you think getRealPath()
is deprecated.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
RE: Problem with ServletContext.getResource()
Posted by Henry Chen <he...@gmail.com>.
This doesn't work. Even getResource(contextPath) doesn't work.
-----Original Message-----
From: Ivano [mailto:i.pagano@mclink.it]
Sent: Thursday, May 05, 2005 10:33 AM
To: Tapestry users
Subject: Re: Problem with ServletContext.getResource()
Could it be:
String somefile = contextPath + File.separator + "abc.zip";
or about the same:
String somefile = contextPath +"/abc.zip";
Henry Chen wrote:
>Hi,
>
>
>
>I want to write to a file. I use the following method:
>
>
>
>String contextPath =
>cycle.getRequestContext().getRequest().getContextPath();
>
>ServletContext context =
>cycle.getRequestContext().getServlet().getServletContext();
>
>String somefile = contextPath +"abc.zip";
>
>String outFileName = context.getResource(somfile).getFile();
>
>
>
>This return a null value for context.getResource(somfile). I tried
>getRealPath(), it worked, but it was deprecated. Anybody knows what the
>problem is here? Or there are some other better ways?
>
>
>
>Many Thanks.
>
>
>
>Henry
>
>
>
>
--
Ivano Pagano
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Problem with ServletContext.getResource()
Posted by Ivano <i....@mclink.it>.
Could it be:
String somefile = contextPath + File.separator + "abc.zip";
or about the same:
String somefile = contextPath +"/abc.zip";
Henry Chen wrote:
>Hi,
>
>
>
>I want to write to a file. I use the following method:
>
>
>
>String contextPath =
>cycle.getRequestContext().getRequest().getContextPath();
>
>ServletContext context =
>cycle.getRequestContext().getServlet().getServletContext();
>
>String somefile = contextPath +"abc.zip";
>
>String outFileName = context.getResource(somfile).getFile();
>
>
>
>This return a null value for context.getResource(somfile). I tried
>getRealPath(), it worked, but it was deprecated. Anybody knows what the
>problem is here? Or there are some other better ways?
>
>
>
>Many Thanks.
>
>
>
>Henry
>
>
>
>
--
Ivano Pagano
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org