title: How to use Session in Java Servlet?
body: <p>I am having issues with session in my java code. Upon submitting a form via post, the java servlet will determine if the captcha is correct. May I know anything that I should add to use the session in java servlet? Is there any thing that I need to import to use session?</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
  try{
      // Validate Captcha
      String userCaptcha = request.getParameter("captcha");
      Captcha captcha = (Captcha) session.getAttribute(Captcha.NAME);
      if (!captcha.isCorrect(userCaptcha)) {
          errorMsgs.add("Please input the correct Captcha value.");
      }
  } catch (RuntimeException e) {
      ...
  }
  ...
  </code></pre>
  
  <p>Thank you very much.</p>