O JSF tem um cara chamado FacesContext, com ele vc tem acesso a muita
informação, como o que veio no request (tanto atributos como
parametros), sessão, e o servletContext:
FacesContext facesContext = FacesContext.getCurrentInstance();
ServletContext servletContext = (ServletContext)
facesContext.getExternalContext().getContext();
String path = servletContext.getRealPath("/");
E não é só vc que esta trabalhando com JSF, aconselho a você dar uma
olhada tb no MyFaces do apache. http://myfaces.apache.org.
Ele tem uns componentes a mais muito interessantes, ja estou usando o
menu, grid paginado, tree, e não para por ai não ;-)
[]s Bula
On 6/30/05, Sylvio Bonelli <[EMAIL PROTECTED]> wrote:
>
> Fala Bulinha!
>
> Obrigado pela resposta, mas tem um porem ; )
>
> Eu estou usando JSF e não tenho, ou pelo menos acho que nao tenho, um
> ServletContext na classe, sabe como resolvo neste caso?
>
> Valeu e um grande abraço!!!!
>
> Bulinha <[EMAIL PROTECTED]> escreveu:
> Essa é fácil :P
>
>
> O ServletContext possui um método chamado getRealPath() (ou algo
> parecido) você passa pra ele qual diretorio virtual que vc quer saber
> o real.
>
> Eu geralmente uso "/" pra pegar o raiz da minha aplicação.
>
> Supondo que vc tenha uma aplicação chamada Teste que esta instalada
> num tomcat (diretorio padrão webapps). E o tomcat esta instalado no
> c:\tomcat, vc usaria:
>
> String dir = contex.getRealPath("/");
> System.out.println(x);
>
> retorno:
> c:\tomcat\webapps\Teste
>
> Espero que tenha ajudado.
>
> []s Bulinha
>
>
>
> On 6/29/05, Sylvio Bonelli wrote:
> >
> >
> > Saudações amigos,
> >
> > Alguem pode me dar um exemplo em java de como pegar um path fisico apartir
> > de um endereço relativo de um site?
> >
> > Pensei que seria simples mas estou dando voltas sem sair do lugar. O
> exemplo
> > é o seguinte:
> >
> > URL Completa:
> > http://blablabla.com.br:8080/templates/file.txt
> >
> > Endereço que posso usar com segurança é "/templates/file.txt" (pois a URL
> > mudará assim que eu colocar o site em producao por exemplo)
> >
> > Agora a grande pergunta, como abrir o arquivo file.txt usando apenas o
> > endereço relativo?
> >
> > No caso seria o equivalente ao ASP e seu Server.MapPath("")
> >
> > Mais uma vez obrigado pela ajuda!!!
> >
> > Sylvio
> >
> > __________________________________________________
> > Converse com seus amigos em tempo real com o Yahoo! Messenger
> > http://br.download.yahoo.com/messenger/
> > ________________________________
> > YAHOO! GROUPS LINKS
> >
> > Visit your group "jug-petropolis" on the web.
> >
> > To unsubscribe from this group, send an email to:
> > [EMAIL PROTECTED]
> >
> > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
> > To unsubscribe from this group, send an email to:
> > [EMAIL PROTECTED]
> >
> > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
> > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
> > ________________________________
> >
> >
> >
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
> ________________________________
> Yahoo! Acesso Grátis: Internet rápida e grátis. Instale o discador agora!
>
> ________________________________
> YAHOO! GROUPS LINKS
>
>
> Visit your group "jug-petropolis" on the web.
>
> To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED]
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
> ________________________________
>
>
>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/jug-petropolis/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/