Java

How to perform HTTP authentication in Servlets2 min read

It is common in web applications to pass data or parameters from one to another page. To retrieve the value of various elements in a HTML form or from another page, we can use the following method which is available in HttpServletRequest object:

  • String getParameters(String  name)
  • Enumeration getParameterName()
  • String[] getParamterValue(String  name)
  1. Client sends a HTTP request from web browsers containing a URL with servlet.
  2. Web server receives the request and forwards the request to application servers.
  3. Using information available in xml (deployment descriptor) the servlet container loads the object appropriate servlet classes.
  4. If required, the servlet retrieves data from database, processes it and sends the response back to web servers.
  5. Web server forward the response back to the client who sent the requests.

Following example demonstrate retrieving data from a login page to a servlet:




login.html

web.xml

Authenticate.java

In the above example we are retrieving the data from login page using the getParameter() method.

Take your time to comment on this article.

Leave a Comment