javaclass
package com.example;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Extend HttpServlet class
public class Helloworld e
Use following :
<servlet>
<servlet-name>HelloForm</servlet-name>
<servlet-class>com.example.Helloworld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloForm</servlet-name>
<url-pattern>/HelloForm</url-pattern>
</servlet-mapping>
and type your url: like localhost:8080/projectName/HelloForm
It may work. And I think you are beginner so go This link . Here is complete tutorial...aboutt this
Now you can switch to servlet 3.0. It's really simple.
@WebServlet("/example")
public class AnnotationServlet extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter prinOut = response.getWriter();
prinOut.write("Hello, This is the first servlet 3 annotation example");
}
}
From Servlet 3.0 Annotation Example in Java
And here is full Java Servlet Tutorial
you haven't specified the package of the servlet class write like this com.example.Helloworld
Your class resides in com.example
So servlet-class should,
<servlet-class>com.example.Helloworld</servlet-class>
You have created servlet class like this:
public class Helloworld extends HttpServlet
But in web.xml you have mapping like this:
<servlet-class>HelloForm</servlet-class>
You need to have same name, so you're getting 404 error. Change either your servlet name to HelloForm
or change <servlet-class>
to HelloWorld
in web.xml
Following way will work.
Create a folder(your poject name,example project) in webapps Inside proect folder create another folder,name it as WEB-INF. Inside WEB-INF past the web.inf file. Create another folder classes inside project folder and keep the .class files. now modify your web.xml as Himanshu Bhardwaj has suggested. restart the server.Then run