• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContext

 
Sruthi Sen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

I am having my application running in the server and i can access it with this URL...
http://localhost:8080/application_name

can i get this URL using any like ServletContext,request etc so that i can print it or use it in another way??

eg: if i say servletContext.getResource() i get the URL like "/localhost/application_name" without port number and protocol.....

is there any method to get that URL or i need to do some String operaions to get URL?

plzz do help

Thank you
kee
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the ServletRequest interface
 
Sruthi Sen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya....i have checked ...but there are methods through which i can get pieces of URL.......

there is no method which gives complete URL

i think i need to concatenat all those pieces to form a Complete URL...

is there any other way other than this .....plzz let me know

Thank you
kee
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably request.getRequestURL() might help.
 
Sruthi Sen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ummm........request.getRequestURL() would work ....

but i can access only ServletRequest,ServletResponse,ServletContext etc but not HttpServletRequest,HttpServletResponse etc


kee
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kee ch,
Welcome to JavaRanch!

We're pleased to have you here with us in the servlets forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As mentioned earlier, what you're looking for can be found the the HttpServletRequest interface:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletRequest.htmlummm........request.getRequestURL()


but i can access only ServletRequest,ServletResponse,ServletContext etc but not HttpServletRequest,HttpServletResponse etc
What does the signature for your doPost/doGet method look like?
[ March 13, 2006: Message edited by: Ben Souther ]
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
provide a utility method which concatenates the required info for you.
 
Sruthi Sen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not writing a servlet.....but a customised taglib's java class...so i dont have access to HttpServletRequest directly..and i am accessing ServeltRequest from pageContext..

I think i should go with concatenation..


Thank you
kee ch
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"kee ch",

You have previously been warned within this very post regarding adjusting your display name to meet JavaRanch standards. This is not optional. Take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

Be aware that accounts with invalid display names are removed.

bear
JavaRanch Sheriff
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kee ch:
i am not writing a servlet.....but a customised taglib's java class..


Then you posted this in the wrong forum. Moved to the JSP forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic