This is my program TimeCheck.java i am developing using NetBeans IDE 6.8
When i run it gives me following error:
Class "TimeCheck" neither has a main method nor it is a servletspecified in web.xml
I didnt find anything specifying Servlet to add so added it here.

following is my TimeCheck.java code:

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Vinken
 */

public class TimeCheck extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {

            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet TimeCheck</title>");  
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet TimeCheck at " + request.getContextPath () + "</h1>");
            out.println("Time is : ");
            out.println("</body>");
            out.println("</html>");

        } finally { 
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

This is the web.xml code where may be the error but i don't know what to add to solve this error
Following is in web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <servlet>
        <servlet-name>TimeCheck</servlet-name>
        <servlet-class>TimeCheck</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TimeCheck</servlet-name>
        <url-pattern>/TimeCheck</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

Is there anyone who can help me with this?
I am new to this & dont know what to do when such kind of error occurs.
It never occured with my friend or in college where i study so just need help to solve this.

Recommended Answers

Did you use NetBeans wizard to setup project or you manually set it up? What server you use? (Tomcat, GlassFish, Jetty,JBoss)

Jump to Post

All 4 Replies

Did you use NetBeans wizard to setup project or you manually set it up? What server you use? (Tomcat, GlassFish, Jetty,JBoss)

i used glassfish v3.0 server

@WebServlet (name="name of servlet",urlPatterns={"/url patter of servlet"})

paste this above your class, if u r using netbeans it should be given by default.

thnx got it
but i am using Netbeans IDE & it wasn't given bydefault

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.