getRequestURL() method Example

getRequestURL() method Example

What is client data?

getRequestURL(): 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, client IP address and also the name of the browser. Also 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 getRequestURL() to retrieve 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.StringBuffer getRequestURL();

Example on getRequestURL()

Client Program: ClientData.html

web.xml entry for ClientInformation servlet

Server Program: ClientInformation.java

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

getme

The output screen when submit button is clicked.

getRequestURL()

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

Leave a Reply

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