title: Spring MVC: Login and logout functions?
body: <p>I am a complete newbie to Spring MVC and need help with login/logout functions. I have the login part figured out (I think), but am still struggling with the logout function. Do I need to establish a session in order to log the user out?</p>
  
  <p>Controller Java file</p>
  
  <pre><code>@RequestMapping(value = "/Login.do")
  public String Login(@ModelAttribute("searchVO") UserInfoVO searchVO, ModelMap model, HttpServletRequest request) throws Exception {
  
      int check = sampleService.loginSample(searchVO);
  
      String username = request.getParameter("registerUsername");
      String password = request.getParameter("registerPassword");
  
      if(check&gt;0&amp;&amp;searchVO.getRegisterUsername()!=null){
          return "forward:/Menu.do";
      }
  
      else{
          return "sample/Login";
      }
  }   
  </code></pre>
  
  <hr>
  
  <p>Login XML File</p>
  
  <pre><code>&lt;select id="leagueDAO.loginSample" parameterClass="userinfoVO" resultClass="int"&gt;
  
          SELECT COUNT(*) totcnt
          FROM REGISTER
          WHERE 1=1   
          AND REGISTERUSERNAME =  #registerUsername# 
          AND REGISTERPASSWORD = #registerPassword#
  
  &lt;/select&gt;
  </code></pre>
  
  <hr>
  
  <p>Login JSP Page</p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%&gt;
  &lt;%@ taglib prefix="c"      uri="http://java.sun.com/jsp/jstl/core" %&gt;
  &lt;%@ taglib prefix="form"   uri="http://www.springframework.org/tags/form" %&gt;
  &lt;%@ taglib prefix="ui"     uri="http://egovframework.gov/ctl/ui"%&gt;
  &lt;%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;link type="text/css" rel="stylesheet" href="&lt;c:url value='/css/egovframework/sample.css'/&gt;"/&gt;
  
      &lt;script type="text/javaScript" language="javascript" defer="defer"&gt;
  
      function doLogin(){
              document.listForm.action = "&lt;c:url value='/Login.do?'/&gt;";
          }
  
      function doRegisterPage(){
          document.listForm.action = "&lt;c:url value='/Register.do?'/&gt;";
  
          }
  
      &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;br/&gt;
  &lt;br/&gt;
  &lt;br/&gt;
  &lt;br/&gt;
      &lt;body style="font-family:Arial; text-align: center; font-size:16px; margin-left:330px;"&gt;
          &lt;form:form commandName="loginForm" id="listForm" name="listForm" method="post"&gt;
                  &lt;h1 style="padding-top: 40px; margin-bottom:-10px; width:280px; height:300px; text-align:center; font-family:Mistral; font-size:56px; color:#000000; margin-top: 50px; margin-left:330px;"&gt;Welcome!
  
                  &lt;br/&gt;
                  &lt;input id="registerUsername" onKeydown="Javascript: if (event.keyCode==13) javascript:doLogin();" align="middle" name="registerUsername" style="border: 5px padding: 8px 0px 0px 2px; margin-top:10px; width:200px; height:30px; font-family:Arial; font-size:18px;" type="text"&gt;&lt;/input&gt;
                  &lt;input id="registerPassword" onKeydown="Javascript: if (event.keyCode==13) javascript:doLogin();" align="middle" name="registerPassword" style="border: 5px padding: 8px 0px 0px 2px; margin-top:10px; width:200px; height:30px; font-family:Arial; font-size:18px;" type="password"&gt;&lt;br/&gt;&lt;/input&gt;
  
                  &lt;button onclick="javascript:doLogin()" style="cursor:pointer; margin-top:20px; width:208px; height:40px; font-family:Arial; font-size: 16px; color: #FFFFFF; background-color: #32CD32;"&gt;Sign In&lt;/button&gt;&lt;br/&gt;
                  &lt;br/&gt;
                  &lt;button onclick="javascript:doRegisterPage()" style="cursor:pointer; margin-bottom:30px;width:208px; height:40px; font-family:Arial; font-size: 16px; color: #FFFFFF; background-color: #0000CD;"&gt;Create Account&lt;/button&gt;&lt;br/&gt;
          &lt;/form:form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>Error message when I add</p>
  
  <pre><code>HttpSession session = request.getSession();
  session.invalidate();
  </code></pre>
  
  <hr>
  
  <pre><code>org.apache.catalina.core.ApplicationDispatcher invoke
  SEVERE: Servlet.service() for servlet action threw exception
  java.lang.StackOverflowError
  at javax.servlet.ServletRequestWrapper.getRemoteAddr(ServletRequestWrapper.java:260)
  </code></pre>