This section gives you the detailed explanation of the getRequestURI() method of the request object in JSP. This method is used for getting the information of the URI of the current page of your JSP application. This method returns the URI of the current page from the URL (Unified Resource Locator). The retrieved URI is the string which is mentioned in the URL after the host name up to the current page. The retrieved URI does not contain the host name or any parameter mentioned from the query string after the page name in the URL.
This section also provides an example of JSP with the complete code which gives you the URI of the current page. You can directly put the code in your JSP application for getting URI as per requirement.
Here is the code of the GetRequestURIMethod.html file:
<html> <body> <form action="GetRequestURIMethod.jsp" method="get"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td>User Name: </td> <td><input type="text" size="20" name= "txtUserName" /> </tr> <tr> <td>Password: </td> <td><input type="password" size="20" name="txtPassword" /> </tr> <tr> <td> </td> <td><input type="submit" value="Submit" name="B1" /></td> </tr> </table> </form> </body> </html>
Output for the GetRequestURIMethod.html file:
Here is the JSP code of the GetRequestURIMehtod.jsp file:
<% out.println("<b>" + request.getRequestURI() + "</b>"); %>
Output for the above mentioned JSP file:
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial
Ask Questions? Discuss: getRequestURI() Method Of The Request Object
Post your Comment