title: Init-param in JavaEE Dynamic Web App returns null
body: <p>Hi if someone could look at my code and maybe see something I am not, this is for a lab for a class assignment of mine. Thank you!</p>
  
  <p>I am programming a simple servlet in a dynamic web project using eclipse. One of the labs requirements is to grab an init parameter from the web.xml in a Servlet.</p>
  
  <p>When I try to get the value of an init-param in my servlet. It keeps returning null.</p>
  
  <p>Anyone see anything wrong that I am not:</p>
  
  <p>im using command:</p>
  
  <pre><code>this.getServletConfig().getInitParameter("title");
  </code></pre>
  
  <p>In class ConvertServlet that is in a00730628.controller package with in the doPost function. I also tried from the init function but got null there to, so I am thinking there is an error in my xml. I am using version 3.0 and Tomcat 7.26</p>
  
  <p>And here is my web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
  
  &lt;display-name&gt;lab10&lt;/display-name&gt;
  
  &lt;welcome-file-list&gt;
  
  &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
  
  &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
  
  &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
  
  &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
  
  &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
  
  &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
  
  &lt;/welcome-file-list&gt;
  
  
  
  &lt;servlet&gt;
  
  &lt;servlet-name&gt;ConvertServlet&lt;/servlet-name&gt; 
  
  &lt;servlet-class&gt;a00730628.controller.ConvertServlet&lt;/servlet-class&gt;
  
  
  
  &lt;init-param&gt;
  
    &lt;param-name&gt;title&lt;/param-name&gt;
  
    &lt;param-value&gt;Temperature Converter Result&lt;/param-value&gt;
  
  &lt;/init-param&gt;
  
  &lt;/servlet&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Edit added my Servlet Code:</p>
  
  <pre><code>package a00730628.controller;
  
  import java.io.IOException;
  
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import a00730628.util.TemperatureConverter;
  import a00730628.view.Lab10Html;
  
  /**
   * Servlet implementation class ConvertServlet
   */
  @WebServlet("/convert")
  public class ConvertServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
      private static final int CEL_2_FAR = 0;
      private static final int FAR_2_CEL = 1;
  
      private String resultTitle = "";
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public ConvertServlet() {
          super();
          // TODO Auto-generated constructor stub
      }
  
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
          response.getWriter().println("&lt;a href='index.html'&gt;Please make a post request from here&lt;/a&gt;");
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
          try {
              resultTitle = this.getServletConfig().getInitParameter("title");
              if (resultTitle == null) {
                  response.sendError(500, "Title param is null ... wa wa wa");
                  return;
              }
              int type = Integer.parseInt(request.getParameter("type"));
              double number = Double.parseDouble(request.getParameter("number"));
              double converted;
              String result = "";
              switch (type) {
                  case CEL_2_FAR:
                      converted = TemperatureConverter.celsiusToFarenheit(number);
                      result = String.format("%f celsius = %f farenheit", number, converted);
                      break;
                  case FAR_2_CEL:
                      converted = TemperatureConverter.farenheitToCelsius(number);
                      result = String.format("%f farenheit = %f celsius", number, converted);
                      break;
  
              }
              response.getWriter().print(Lab10Html.getLab10Html(resultTitle, result));
          } catch (NumberFormatException e) {
              response.sendError(400, "Please enter a number like 42. Number format error: "+ e.getMessage());
          }
  
  
      }
  
  }
  </code></pre>