Results 1 to 4 of 4

Thread: Is it possible to get the current URL in my JSP page

  1. #1
    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.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    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];
    }

  3. #3
    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>

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    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>

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,971,801.37578 seconds with 16 queries