Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 19-05-2009
Member
 
Join Date: Feb 2008
Posts: 624
Is it possible to get the current URL in my JSP page

I'm new to jsp. I want the current JSP file name. So is it possible to get the current URL in my JSP page? Basically I want to use it somewhere in my application.
Reply With Quote
  #2  
Old 19-05-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Is it possible to get the current URL in my JSP page

The Location Object is a JavaScript class that is used to store URLs. The window.location object is the specific object that stores the URL of the currently loaded page. The URL is stored as protocol://host/pathname.

To get the URL use this code:

pathArray = window.location.pathname.split( '/' );

newPathname = "";
for ( i = 0; i pathArray.length; i++ ) {
newPathname += "/";
newPathname += pathArray[i];
}
Reply With Quote
  #3  
Old 19-05-2009
Member
 
Join Date: May 2008
Posts: 685
Re: Is it possible to get the current URL in my JSP page

JSP Get URL is used to get the url of the current JSP page. The HttpServletRequest interface has a method getRequestURL ( ) that returns the url of the current page. The returned URL contains a protocol, server name, port number, and server path. Because this method returns a StringBuffer, you can modify the URL easily, for example, to append query parameters.

HTML Code:
<html>
<head>
<title>Get URL</title>
</head>
<h2>Get URL of Current JSP</h2>
URL is: <font color="red"><%=request.getRequestURL()%></font>
</html>
Reply With Quote
  #4  
Old 19-05-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Is it possible to get the current URL in my JSP page

The following script generates the current url of the page

HTML Code:
<SCRIPT LANGUAGE="JavaScript">
  
      <!--
      {
       document.write(location.href);
      }
      // -->
</SCRIPT>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Is it possible to get the current URL in my JSP page"
Thread Thread Starter Forum Replies Last Post
Cannot change homepage in Firefox 12 to 'use current page' Cheeru Technology & Internet 6 29-04-2012 03:21 PM
develop web report: display Current page and Total pages freezea Software Development 1 25-05-2011 12:03 AM
My current home page doesn't display on desktop matbiec Window 2000 Help 2 29-12-2010 12:40 AM
How do I get the URI of the current web page from my Drupal theme? Bambina Technology & Internet 4 28-01-2010 04:12 PM
How to find out Current Page Url with the help of JavaScript? Kushan Software Development 3 21-11-2009 10:40 AM


All times are GMT +5.5. The time now is 03:09 AM.