0

I am new to JAVA development.

I have created a simple Servlet called 'test'. But It does not work after deployment.

package com.MyServlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/test")
public class test extends HttpServlet {
    private static final long serialVersionUID = 1L;
   
    public test() {
        super();
        // TODO Auto-generated constructor stub
    }

    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        response.setContentType("text/html");  
        PrintWriter pw= response.getWriter();  
        pw.println("<h1>This is get request.</h1>");
    }

    
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        response.setContentType("text/html");  
        PrintWriter pw= response.getWriter();  
        pw.println("<h1>This is post request.</h1>");
        
    }

}

its works in Eclipse with Apache Tomcat. But after deployment on Apache Tomcat, it gives the error " error instantiating servlet class".

deploy using .war file

Version is Tomcat 9.0.54 on both server and eclipse PC.

The operating system Win 10 and also tired on win server 2016.

At First time when I run Servlet, it gives an error Error instantiating servlet class [com.MyServlets.test] here I have uploaded a full error screenshot enter link description here

And When I try to access the same servlet second time I get this The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. Here I have uploaded a full error screenshot enter link description here

Example servlet is working properly just addition deployed servlet not working on Apache tomcat 9

I have also tried apache tomcat 10

import jakarta.servlet.*;
import jakarta.servlet.http.*;

And I have tried enter link description here

Roank1112
  • 29
  • 4

0 Answers0