title: Passing hidden input value from jsp to servlet
body: <p>I'm trying to generate an excel file when a link is clicked without being redirected anywhere. I make it into the servlet but when I try to get the value of a hidden input, I get a null pointer exception. The code I'm using is</p>
  
  <p>JSP</p>
  
  <pre><code>&lt;html:form action="/UploadExcel.do" enctype="multipart/form-data" method="post"&gt;
  &lt;a href="#" onclick="ExcelFiller.fill"&gt;Download Excel&lt;/a&gt;
  &lt;input type="hidden" name="refBgcId" id="refBgcId" value="84"&gt;&lt;/input&gt;
  &lt;/html:form&gt;
  </code></pre>
  
  <p>Servlet</p>
  
  <pre><code>public class ExcelFiller extends HttpServlet {
  private static final long serialVersionUID = 1L;
  
  public void init(ServletConfig config) throws ServletException {    
      super.init(config);
  }
  
  public void destroy() {
  
  }
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      System.out.println("Made it to the servlet");
      doPost(request,response);
  }
  
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      System.out.println("In doPost");
      HttpSession session=(HttpSession) request.getSession(false);
  
      String loggedInUserId = (String)session.getAttribute("strUserId");
      try{
          String referenceid = request.getParameter("refBgcId").toString();/*NULL POINTER EXCEPTION*/
          ArrayList&lt;String&gt; details = new ArrayList&lt;String&gt;(); 
          details = UploadBGCDAO.getDetails(referenceid);
          createExcel(request,response,details, loggedInUserId);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  }
  </code></pre>
  
  <p>I have tried finding the solution in the answers to similar questions on this site but I still can't make this work. Can someone please tell me what I'm doing wrong?</p>