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:
Ask Questions? Discuss: getRequestURI() Method Of The Request Object
Post your Comment
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.