title: How to programmatically login to j_security_check
body: <p>I have a JSP web application which uses <code>j_security_check</code>. Is it possible to login a specific user to <code>j_security_check</code> programmatically via a JSP page if I know the userid and password? I tried to pass the variables as URL parameters this way...</p>
  
  <pre><code>response.sendRedirect(www.mydomain.com/j_security_check?j_username=someUserName&amp;j_password=somePassword )
  </code></pre>
  
  <p>...but it doesn't work. Is there any way to do it?</p>
  
  <p>Edit:
  here is my login page which works fine right now. I trimmed some of the code for security reasons.</p>
  
  <pre><code>    &lt;form name="signon" method="post" action="/j_security_check"&gt;
        &lt;table width="100%" cellpadding="4" cellspacing="0"&gt;
  
          &lt;tr&gt;
            &lt;td valign="top" colspan="4"&gt;
              &lt;h2&gt;&lt;%= UI.tr(null, "login_details") %&gt;
              &lt;/h2&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
            &lt;td valign="top" width="150px"&gt;
              &lt;%= UI.tr(null, "login_id") %&gt;
            &lt;/td&gt;
            &lt;td valign="top" width="150px"&gt;
              &lt;%= UI.tr(null, "login_pass") %&gt;
            &lt;/td&gt;
            &lt;td valign="top" width="150px"&gt;
              &lt;%= UI.tr(null, "login_token_or_captcha") %&gt;
            &lt;/td&gt;
            &lt;td width="100%"&gt;&amp;nbsp;&lt;/td&gt;
          &lt;/tr&gt;
  
  
          &lt;tr&gt;
  
            &lt;%
              if (logins == null) {
            %&gt;
            &lt;td&gt;
              &lt;input type="hidden" name="j_uri" value="/index.jsp"&gt;
              &lt;input type="text" id="username" name="j_username" size="16" style="width: 150px;" autocomplete="off" &lt;%= username == null ? "" : "disabled value='" + username + "'" %&gt; onblur="return checkCaptcha();"&gt;
            &lt;/td&gt;
            &lt;%
            } else {
            %&gt;
            &lt;td&gt;
              &lt;select name="j_username" style="width: 150px;"&gt;
                &lt;%
                  for (Login login : logins) {
                %&gt;
                &lt;option&gt;&lt;%= login.getUsername() %&gt;
                &lt;/option&gt;
                &lt;%
                  }
                %&gt;
              &lt;/select&gt;
            &lt;/td&gt;
            &lt;%
              }
            %&gt;
            &lt;td&gt;&lt;input type="password" name="j_password" size="16" style="width: 150px;"&gt;                &lt;/td&gt;
            &lt;td&gt;&lt;input type="text" id="mypw" name="mypw" size="16" autocomplete="off" style="width: 150px;"&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input class="submit" type="submit" name="submit" value="&lt;%= UI.tr(null, "login_submit") %&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
  
  
  
  &lt;tr&gt;
    &lt;td valign="top" colspan="4"&gt;
      &lt;%-- &lt;%
      if("registry.nic.hn".equals(request.getServerName())) {
      %&gt;
      &lt;!-- GARTH - put whatever you want here for .HN --&gt;
      &amp;nbsp;
      &lt;% } else { %&gt; --%&gt;
          &lt;h2&gt;&lt;%= UI.tr(null, "login_news") %&gt;
          &lt;/h2&gt;
          &lt;div&gt;&lt;%= HTMLFormat.addBreaks(SiteConf.getSiteConf().getNews()) %&gt;
          &lt;/div&gt;
      &lt;%-- &lt;% } %&gt;     --%&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>
  </p>