Interview Questions

Web Application Auto Login

In general, every web application will have an authentication mechanism, to authenticate the users accessing the web application.

Suppose if there is a requirement to autologin to a web application from a given page, use the following code.

<script type="text/javascript">

function autoLogin()
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
          alert("Response received --> "+xmlhttp.responseText);
   var url = "http://localhost:8080/webAppName/login.jsp?username=<userName>&password=<password>";// url to auto login a web Application"POST",url,true);




The above code uses ajax to make a post request to the web app with username and password. Three things we need to know for auto login are as follows

1.) url of the web application
2.) relative url to make the post request
3.) usename/password along with the parameter names for username and password for making post request.

If the login attempt was successful, the user will be redirected to the web app page after successful login.