title: Java web servlet not working
body: <p>I have a real webpage using cPanel hosting where I am starting out with learning java web dev. I only use two files: index.jsp &amp; FirstServlet.java. The <strong>HTML page is just not using the Java code</strong> and I am not quite sure why, I got the code from a demo to have a starting reference.</p>
  
  <p>index.jsp:</p>
  
  <pre><code>&lt;%@page import="java.util.Date"%&gt;
  &lt;%@ page language="java" contentType="text/html; charset=US-ASCII"
      pageEncoding="US-ASCII"%&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=US-ASCII"&gt;
          &lt;title&gt;Hello&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h2&gt;Hi There!&lt;/h2&gt;
          &lt;br&gt;
          &lt;h3&gt;Date=&lt;%= new Date() %&gt;
          &lt;/h3&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>FirstServlet.java:</p>
  
  <pre><code>package com.journaldev.first;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Date;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebInitParam;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * Servlet implementation class FirstServlet
   */
  @WebServlet(description = "My First Servlet", urlPatterns = { "/FirstServlet" , "/FirstServlet.do"}, initParams = {@WebInitParam(name="id",value="1"),@WebInitParam(name="name",value="pankaj")})
  public class FirstServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
      public static final String HTML_START="&lt;html&gt;&lt;body&gt;";
      public static final String HTML_END="&lt;/body&gt;&lt;/html&gt;";
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public FirstServlet() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          PrintWriter out = response.getWriter();
          Date date = new Date();
          out.println(HTML_START + "&lt;h2&gt;Hi There!&lt;/h2&gt;&lt;br/&gt;&lt;h3&gt;Date="+date +"&lt;/h3&gt;"+HTML_END);
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
      }
  
  }
  </code></pre>
  
  <p><strong>Result:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/wEFv8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wEFv8.png" alt="enter image description here"></a></p>