-1

I created a Servlet Program using Servlet Interface and I am just Sending my response to the Browser using response interface method getWriter() which returns PrintWriter reference and I am trying to print the following Information such as Hello and a Date on the Browser.

But,I am getting a following 404 Error.

Can anyone guide me Why?

Code for my Servlet Program.

class FirstAppUsingServlet  implements Servlet 
{

    public void init(ServletConfig config) throws ServletException 
    {
    }


    public void destroy() 
    {
    }


    public ServletConfig getServletConfig() 
    {
        return null;
    }


    public String getServletInfo() 
    {
        return null; 
    }


    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
     {
         Date d1=new Date();
         System.out.println(d1);
         PrintWriter out=response.getWriter();
         out.println("Hello Java");
         out.println(d1);
     }

}

Code for the web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
 <display-name>FirstServletApp</display-name>


 <servlet>
 <description></description>
 <display-name>FirstAppUsingServlet</display-name>
 <servlet-name>FirstAppUsingServlet</servlet-name>
 <servlet-class>FirstAppUsingServlet</servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>FirstAppUsingServlet</servlet-name>
 <url-pattern>/FirstAppUsingServlet</url-pattern>
 </servlet-mapping>
 </web-app>

And the Following error: http://localhost:8089/FirstServletApp/WEB-INF/classes/FirstAppUsingServlet.java enter image description here

user207421
  • 305,947
  • 44
  • 307
  • 483
Jason arora
  • 550
  • 3
  • 8
  • 22
  • 1
    url should be http://localhost:8089/FirstServletApp/FirstAppUsingServlet – sdfacre Apr 06 '16 at 01:22
  • Your class should extend `HttpServlet`. `init(ServletConfig config)` must call `super(config)`: see the Javadoc. `getServletInfo()` cannot return null, and neither can `getServletConfig()`. – user207421 Apr 06 '16 at 01:30
  • @sdfacre Yes you are right:Why it is taking the path when I am using other Applications it is not taking the path of Web-Inf/classes folder. – Jason arora Apr 06 '16 at 02:12
  • The path is what you defined in web.xml, that's what servlet-mapping and url-pattern for. everything under web-inf is not public. – sdfacre Apr 06 '16 at 03:40

1 Answers1

-1

Do couple of things:

  1. First check whether TOMCAT server started properly or not. For this, check http://localhost:8080/ from the browser. I am assumming you have started server on 8080 port. If Server is started properly, then you will see TOMCAT home page. If it is not, then you have to check JAVA_HOME environmental variable setting.

  2. Check if you have any error on console page of your editor.

  3. Check if your URL is correct because you haven't pasted URL here.

Ashish Patil
  • 4,428
  • 1
  • 15
  • 36
  • 1)All Other programs are working properly. 2)No Error on Console: 3)I have pasted the Url.My all other ServletPrograms such as with Generic and HttpServlet servlet are working properly. – Jason arora Apr 06 '16 at 01:05
  • If (1) was the problem he could not possibly get this error. (2) doesn't mean anything. – user207421 Apr 06 '16 at 02:55