title: How can I register a servlet with Spring Boot?
body: <p>This code don't work</p>
  
  <p>I have a web.xml that needs to be translated into a spring boot</p>
  
  <pre><code>    &lt;servlet&gt;       
              &lt;servlet-name&gt;page-resolver&lt;/servlet-name&gt;       
              &lt;servlet-class&gt;com.bk.ForwardServlet&lt;/servlet-class&gt;         
              &lt;init-param&gt;
                  &lt;param-name&gt;page&lt;/param-name&gt;
                  &lt;param-value&gt;/index.jsp&lt;/param-value&gt;         
              &lt;/init-param&gt;         
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;                            
          &lt;servlet-name&gt;page-resolver&lt;/servlet-name&gt;         
          &lt;url-pattern&gt;/index.html&lt;/url-pattern&gt;
          &lt;url-pattern&gt;/login&lt;/url-pattern&gt;
          &lt;url-pattern&gt;/qmgr/*&lt;/url-pattern&gt;  
      &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>and this class</p>
  
  <pre><code>@WebServlet
  public class ForwardServlet extends HttpServlet {
  
  private String page;
  
  @Override
  public void init(ServletConfig config) throws ServletException {
      super.init(config);
      page = config.getInitParameter("page");
  }
  
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      req.getRequestDispatcher(page).forward(req, resp);
  }
  }
  </code></pre>
  
  <p>I wrote code that registers this bean but it doesn't work and I don't understand why</p>
  
  <pre><code>@Configuration
  public class ConfigureWeb implements ServletContextInitializer {
  
  private void registerServlet(ServletContext servletContext) {
      ServletRegistrationBean serviceServlet =
              new ServletRegistrationBean(new ForwardServlet(), "/index.html","/login","/qmgr/*");
  
      serviceServlet.addUrlMappings("/index.jsp");
  }
  
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
      registerServlet(servletContext);
  }
  }
  </code></pre>