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.
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.
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];
}
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>
The following script generates the current url of the page
HTML Code:<SCRIPT LANGUAGE="JavaScript"> <!-- { document.write(location.href); } // --> </SCRIPT>
Bookmarks