getRequestURI() Method Example

getRequestURI() Method Example


What is client data?

When the user clicks the submit button, we think that the data entered by the user like user name and password are sent to the server. Ofcourse, right. But along with it, lot of client data goes to the server. The client data includes the protocol used by the client to access the server, client IP address and also the name of the browser client is using, its version (headers) etc.

Is there anyway to retrieve client data from the servlet?

Yes, HttpServletRequest interface comes with many methods to retrieve the client data.

This program uses getRequestURI() to retrieve the a part of the URL used by the client to call the servlet on the server.

Following is the method signature as defined in HttpServletRequest interface.

public abstract java.lang.String getRequestURI();

Example on getRequestURI()

Client Program: ClientData.html

web.xml entry for ClientInformation servlet

Server Program: ClientInformation.java

Following is the method signature as defined in HttpServletRequest interface.

public abstract java.lang.String getRequestURI();

Output screen of ClientData.html with text field filled up.

getRequestURI()

The output screen when submit button is clicked.

ima

Observe, the getRequestURI() prints a portion of the URL (written in ACTION attribute of FORM tag) used by the client to call the servlet. This is where getRequestURL() differs from getRequestURI().

View All Servlets

Leave a Reply

Your email address will not be published. Required fields are marked *