title: Servlet init-parameter always shows null
body: <p>I'm a java2ee absolute beginner and I'd need some help.
  I'm following a youtube-tutorial ( <a href="https://www.youtube.com/watch?v=sB7-ChpjWVw" rel="nofollow noreferrer">https://www.youtube.com/watch?v=sB7-ChpjWVw</a> ) and I also have some really basic knowledge about the topic.</p>
  
  <p>The point is: 
  No matter how I try, whenever I try to show a servlet-init-parameter from web.xml into my servlet it always ends showing null value.
  curious fact: no problem occurs when I do the same with context-parameters.</p>
  
  <p>I've tried overriding the init() method instead of the init(ServletConfig config) method. 
  if I override the init(ServletConfig config) method I call the super.init(config).
  I've tried to move everything inside the doGet() method.
  the project is already set up as a dynamic web project.
  I've used each and every version of the getInitParameter(String) method I found on StackOverflow.</p>
  
  <p>all that comes to my mind is something could be wrong in the pom file ( maybe some old dependency ? some missing plugin ? ).</p>
  
  <p>here's the code for the web.xml, the servlet, and the pom.</p>
  
  <p>please save me, I've been on this for 48 hours now.</p>
  
  <p>here's the servlet </p>
  
  <pre><code>package servlet;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Date;
  
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * Servlet implementation class MyFirstServlet
   */
  @WebServlet("/MyFirstServlet")
  public class MyFirstServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
  
  private ServletConfig servletConfig;
  private String servletInitParameterValue;
  private String contextParameterValue;
  
  private String loginTime;
  
  /**
   * @see HttpServlet#HttpServlet()
   */
  public MyFirstServlet() {
      super();
      // TODO Auto-generated constructor stub
  }
  
  /**
   * @see Servlet#init(ServletConfig)
   */
  public void init(ServletConfig config) throws ServletException {
  
      System.out.println("Basic servlet***********************init()******************");
      super.init(config);
      this.servletConfig=config;
  
      //use ServletConfig to get servlet init parameters
      servletInitParameterValue =  getServletConfig().getInitParameter("parInit");
      System.out.println("servletInitParameterValue = "+ servletInitParameterValue);
  
  
      //use ServletConfig to get context init parameters
      contextParameterValue = config.getServletContext().getInitParameter("ContextParameter");
      System.out.println("contextParameterValue = "+ contextParameterValue );
  
  }
  
  
  
  
  
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
      System.out.println("Basic servlet***********************doGet()******************");
  
  
  
  
      // get request parameter
      String requestParamValue = request.getParameter("param");
  
      //set response content type
      response.setContentType("text/html");
  
  
      //create web-page and write a message inside of it
      response.getWriter().append("Served at: ").append(request.getContextPath());
      PrintWriter out = response.getWriter();
          out.println("&lt;html&gt;");
          out.println("&lt;body&gt;");
          out.println("&lt;br&gt;");
          out.println("&lt;h3&gt;"+this.getSerlvletInfo() + " invoked at " + new Date().getDate()+". "+ " i got init param "+ servletInitParameterValue
                  + " and context param = "+ contextParameterValue + ".&lt;br&gt;"+"You logged in passing parameter value param as "+ requestParamValue
                  +"&lt;/h3&gt;"+ ".&lt;br&gt;");
  
          out.println("&lt;a href='ExeServlet'&gt;vai a seconda servlet&lt;/a&gt;");
          out.println("&lt;/html&gt;");
          out.println("&lt;/body&gt;");
  
  
  }
  
  
  
  
  
  
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      doGet(request, response);
  }
  
  
  
  
  
  
  
  /**
   * @see Servlet#destroy()
   */
  public void destroy() {
      System.out.println("i'm destroyed!");
  }
  
  
  public String getSerlvletInfo () {
      return this.servletConfig.getServletName();
  }
  
  public ServletConfig getServletConfig () {
      return servletConfig;
  }
  
  
  }
  </code></pre>
  
  <p>here's the web.xml</p>
  
  <pre><code>&lt;!DOCTYPE web-app PUBLIC
  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
  "http://java.sun.com/dtd/web-app_2_3.dtd" &gt;
  
  
  
  
  &lt;web-app&gt;
    &lt;display-name&gt;Archetype Created Web Application&lt;/display-name&gt;
  
  
    &lt;context-param&gt;
          &lt;param-name&gt;country&lt;/param-name&gt;
          &lt;param-value&gt;Ita&lt;/param-value&gt;
      &lt;/context-param&gt;
  
    &lt;context-param&gt;
          &lt;param-name&gt;ContextParameter&lt;/param-name&gt;
          &lt;param-value&gt;IO SONO IL PARAMETRO DI CONTESTO 2&lt;/param-value&gt;
      &lt;/context-param&gt;
  
  
  
    &lt;servlet&gt;
           &lt;servlet-name&gt;MyFirstServlet&lt;/servlet-name&gt;
       &lt;display-name&gt;MyFirstServlet&lt;/display-name&gt;
       &lt;description&gt;&lt;/description&gt;
      &lt;servlet-class&gt;servlet.MyFirstServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;parInit&lt;/param-name&gt;
      &lt;param-value&gt;IO SONO IL PARAMETRO DELLA SERVLET&lt;/param-value&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;/init-param&gt;
   &lt;/servlet&gt;
   &lt;servlet&gt;
      &lt;servlet-name&gt;ExeServlet&lt;/servlet-name&gt;
  &lt;display-name&gt;ExeServlet&lt;/display-name&gt;
  &lt;description&gt;&lt;/description&gt;
  &lt;servlet-class&gt;servlet.ExeServlet&lt;/servlet-class&gt;
  &lt;init-param&gt;
      &lt;param-name&gt;company&lt;/param-name&gt;
      &lt;param-value&gt;thewebbcompany&lt;/param-value&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;/init-param&gt;
     &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;MyFirstServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/servlet/MyFirstServlet&lt;/url-pattern&gt;
     &lt;/servlet-mapping&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;ExeServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/ExeServlet&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
   &lt;/web-app&gt;
  </code></pre>
  
  <p>and here comes the pom</p>
  
  <pre><code>                &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
                &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
                &lt;groupId&gt;com.theStartupCentral&lt;/groupId&gt;
                &lt;artifactId&gt;pizzashoppingcart&lt;/artifactId&gt;
                &lt;packaging&gt;war&lt;/packaging&gt;
                &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
                &lt;name&gt;pizzashoppingcart Maven Webapp&lt;/name&gt;
                &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
  
  
  
                &lt;dependencies&gt;
                  &lt;dependency&gt;
                    &lt;groupId&gt;junit&lt;/groupId&gt;
                    &lt;artifactId&gt;junit&lt;/artifactId&gt;
                    &lt;version&gt;3.8.1&lt;/version&gt;
                    &lt;scope&gt;test&lt;/scope&gt;
                  &lt;/dependency&gt;
                  &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-core --&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
                  &lt;version&gt;5.1.3.RELEASE&lt;/version&gt;
              &lt;/dependency&gt;
                  &lt;!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;mysql&lt;/groupId&gt;
                  &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
                  &lt;version&gt;5.1.6&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
                  &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
                  &lt;version&gt;4.0.1&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;!-- https://mvnrepository.com/artifact/javax.servlet/jstl --&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
                  &lt;artifactId&gt;jstl&lt;/artifactId&gt;
                  &lt;version&gt;1.2&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;!-- https://mvnrepository.com/artifact/javax.validation/validation-api --&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;javax.validation&lt;/groupId&gt;
                  &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
                  &lt;version&gt;1.0.0.GA&lt;/version&gt;
              &lt;/dependency&gt;
  
  
  
                &lt;/dependencies&gt;
  
                &lt;build&gt;
                  &lt;plugins&gt;
                      &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                      &lt;version&gt;3.1&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;source&gt;1.8&lt;/source&gt;
                          &lt;target&gt;1.8&lt;/target&gt;
                           &lt;fork&gt;true&lt;/fork&gt;
                      &lt;executable&gt;C:\Program Files\Java\jdk1.8.0_191\bin\javac&lt;/executable&gt;    
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
  
  
  
              &lt;/project&gt;
  </code></pre>