0

I am new to JAVA development.

I have created a simple Servlet called 'test'.

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".

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

My other JSP page works properly on the same Apache Tomcat.

I tried enter link description here It still has not worked

Roank1112
  • 29
  • 4
  • 2
    Which version of tomcat do you have in eclipse, and which one is it where it doesn't work? Also, can you provide more detailed error message, e.g. from the log? – Olaf Kock Oct 30 '21 at 12:37
  • 1
    e.g. if deployment doesn't work on Tomcat 10: Check https://stackoverflow.com/q/64387472/13447 – Olaf Kock Oct 30 '21 at 13:12
  • Always search Stack Overflow thoroughly before posting. If similar Questions exist, explain how they do not address your issue. – Basil Bourque Oct 30 '21 at 18:22
  • Virson is Tomcat 9.0.54. – Roank1112 Nov 01 '21 at 03:24
  • 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 [link](https://ibb.co/BBNN4Sg). & 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 [link](https://ibb.co/2PNV98p). – Roank1112 Nov 01 '21 at 03:37
  • Does [Tomcat - UnsupportedClassException](https://stackoverflow.com/q/1907015/11748454) answer your question? – Piotr P. Karwasz Nov 01 '21 at 08:19

0 Answers0