aspose file tools*
The moose likes JSP and the fly likes ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "ServletContext" Watch "ServletContext" New topic
Author

ServletContext

Sruthi Sen
Greenhorn

Joined: Dec 20, 2005
Posts: 22
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Check out the ServletRequest interface


[My Blog]
All roads lead to JavaRanch
Sruthi Sen
Greenhorn

Joined: Dec 20, 2005
Posts: 22
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

Joined: Apr 13, 2003
Posts: 1088
Probably request.getRequestURL() might help.
Sruthi Sen
Greenhorn

Joined: Dec 20, 2005
Posts: 22
ummm........request.getRequestURL() would work ....

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


kee
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Feb 11, 2006
Posts: 288
provide a utility method which concatenates the required info for you.


java j2ee job interview questions with answers | Learn the core concepts and the key areas
Sruthi Sen
Greenhorn

Joined: Dec 20, 2005
Posts: 22
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

Joined: Jan 10, 2002
Posts: 61657
    
  67

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServletContext