title: Returning back to login page while login page automation
body: <p>I am trying to automate login to my institute website using JSoup. I tried doing with the tutorial present at <a href="https://www.javacodeexamples.com/jsoup-login-to-website-using-post-method-example/830" rel="nofollow noreferrer">https://www.javacodeexamples.com/jsoup-login-to-website-using-post-method-example/830</a></p>
  
  <p>But every time i do it, the elements of the same webpage(login page) is returned and not of my dashboard. seems like i am unable to login, although the login credentials are correct and working on the website.</p>
  
  <p>below is my code </p>
  
  <pre><code>String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
      try {
  
          //grab login form page first
          Response loginPageResponse = 
                  Jsoup.connect("https://www.icloudemserp.com/corecampus/checkuser1.php")
                  .referrer("https://www.icloudemserp.com/corecampus/index.php/")
                  .userAgent(userAgent)
                  .timeout(10 * 1000)
                  .followRedirects(true)
                  .method(Connection.Method.GET)        
                  .execute();
  
          System.out.println("Fetched login page");
  
          //get the cookies from the response, which we will post to the action URL
          Map&lt;String, String&gt; mapLoginPageCookies = loginPageResponse.cookies();
          String YOUR_USER_ID = "MREI2033";
          String YOUR_PASSWORD = "student1234";
          String branch_id = "9";
          //lets make data map containing all the parameters and its values found in the form
          Map&lt;String, String&gt; mapParams = new HashMap&lt;String, String&gt;();
          mapParams.put("branchid", "1");
          mapParams.put("userid", "");
          mapParams.put("pass_word", "");
          mapParams.put("branchid", "9");
          mapParams.put("sel_acad_yr", "2013-2014");
          mapParams.put("sel_sem", "Sem+1");
  
          System.out.println("*****************************************"+YOUR_USER_ID+YOUR_PASSWORD);
          //URL found in form's action attribute
          String strActionURL = "https://www.icloudemserp.com/corecampus/checkuser1.php";
  
          Response responsePostLogin = Jsoup.connect(strActionURL) 
                  //referrer will be the login page's URL
                  .referrer("https://www.icloudemserp.com/corecampus/index.php/")
                  //user agent
                  .userAgent(userAgent)
                  //connect and read time out
                  .timeout(10 * 1000)
                  //post parameters
                  .data(mapParams)
                  //cookies received from login page
                  .cookies(mapLoginPageCookies)
                  //many websites redirects the user after login, so follow them
                  .followRedirects(true)
                  .method(Connection.Method.POST)
                  .execute();
  
          System.out.println("HTTP Status Code: " + responsePostLogin.statusCode());
  
          //parse the document from response
          Document document = responsePostLogin.parse();
          System.out.println(document);
  
          //get the cookies
          Map&lt;String, String&gt; mapLoggedInCookies = responsePostLogin.cookies();
  
          /*
           * For all the subsequent requests, you need to send
           * the mapLoggedInCookies containing cookies
           */
           Document doc = Jsoup.connect("https://www.icloudemserp.com/corecampus/student/student_index.php")
          .cookies(mapLoggedInCookies)
          .userAgent(userAgent)
          .get();
          System.out.println("##################################################");
          System.out.println(doc);
      }
  </code></pre>
  
  <p>Thanks for help:)</p>