getScheme() Method Example

getScheme() Method Example


getScheme() method is defined in ServletRequest interface from javax.servlet package inherited by HttpServletRequest.

With getScheme() method, the Servlet Programmer can know what protocol (like HTTP) is used by the client from HTML file to call the Servlet.

Let us see what Java API says about this method.

  • public java.lang.String getScheme(): Returns the name of the scheme used to make this request, for example, http, https, or ftp. Different schemes have different rules for constructing URLs, as noted in RFC 1738.

The method getScheme() returns a string, the protocol used in ACTION attribute of of FORM tag used by the client to call the servlet.

Let us see the output by writing a program.

HTML Program: ClientData.html

Observe, the client uses GET value for attribute METHOD.

web.xml entry for ClientInformation servlet

Servelet Program: ClientInformation.java

Output screen of ClientData.html with text field filled up. Anyhow, the text field does not have any purpose here.

getScheme()

The output screen when submit button is clicked.

ima

To get the protocol with version, use getProtocol() method.

Leave a Reply

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