title: Accessing request scoped bean inside servlet
body: <p>I have a jsp page where i am using a bean as request scope bean. I have an input text whose value is the attribute of the bean. On the form submit my action is someServlet. Now in that someServlet i want to access the bean that i used in my jsp page.
  here is sample code i am using.</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;jsp:useBean id="userBean" scope="request" class="com.iceman.bean.UserBean"&gt;
  &lt;jsp:setProperty property="*" name="userBean"/&gt;&lt;/jsp:useBean&gt;
      &lt;form action="action.do" method="post"&gt;
          Type Your Name:&lt;input type="text" name="userName"/&gt;&lt;br/&gt;
          &lt;input type="submit" value="Submit"/&gt; 
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Servler</strong></p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
          UserBean userBean = (UserBean)request.getAttribute("userBean");
          response.getWriter().print(userBean.getUserName());
      }
  </code></pre>
  
  <p>When i run this i get a null pointer exception on servlet line where i call bean getter method.</p>
  
  <p>Where am i doing wrong?</p>