Pegar o "cidade" do http://localhost:8080/cidade

5 respostas
xivan

Olá pessoal o título diz tudo…

Como faço para pegar o “cidade” do do http://localhost:8080/cidade no JSP.

Sem usar servlet. Apenas pegar o nome literal… exemplo http://localhost:8080/saopaulo

Eu poder pegar o saopaulo para fazer o select.

Obrigado.

5 Respostas

Roger75

Tente assim:

String url="http://localhost:8080/saopaulo";
String arrURL=url.split("/");


int len=arrURL.length;

//A parte procurada:
String procurada=arrURL[len-1];
Felagund
Roger75:
Tente assim:
String url="http://localhost:8080/saopaulo";
String arrURL=url.split("/");


int len=arrURL.length;

//A parte procurada:
String procurada=arrURL[len-1];

viu, vc ta brincando né. eu ri disso ai.

Ele quer pegar dinamico não fixo...

xivan

A idéia é pegar dinâmico. E também queria saber como quando for chamado http://localhost:8080/cidade ele entrar no jsp principal.jsp e fazer a consulta pela cidade.

Roger75

Pelo request você consegue pegar algumas informações da url:

request.getServletPath() request.getServerName()

thiago.correa

Dê uma Lida em REST

Criado 30 de setembro de 2010
Ultima resposta 1 de out. de 2010
Respostas 5
Participantes 4