The Artima Developer Community
Sponsored Link

Java Answers Forum
how to get the context information

1 reply on 1 page. Most recent reply: Apr 5, 2002 3:46 PM by Jay Kandy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Binod Pokharel

Posts: 9
Nickname: binod
Registered: Mar, 2002

how to get the context information Posted: Apr 5, 2002 10:13 AM
Reply to this message Reply
Advertisement
Hi,

It may be a small problem but from my jsp page, I need to get the base URL information. For example if I am running my web application in localhost , I need
http://localhost:8080/myapp

How do we do this ?

I was trying <%= request.getServerName() %>
and <%= request.getServletContext()%>

but all had some or the other problem. It is not fixed, what I want is fixed base URL always.

Bye
Binod


Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: how to get the context information Posted: Apr 5, 2002 3:46 PM
Reply to this message Reply
String contextPath = request.getServletPath();
String requestURL = ( new HttpUtils().getRequestURL(request) ).toString();
String hostContext = requestURL.substring(0, requestURL.indexOf(contextPath) );


If you have a newer version of Servlet package, (HttpUtils is deprecated as of 2.3 API) use this:
String requestURL =  (request.getRequestURL()).toString();

Flat View: This topic has 1 reply on 1 page
Topic: JAVA implementation For CORBA Previous Topic   Next Topic Topic: How to plot 2D graphs using java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use