'My class files inside WEB-INF/classes gets deleted when i load my webapp in webapps folder [duplicate]
I am using Tomcat 5, when I start the server and load my app from webapp folder, my JSP loads but class files inside the WEB-INF/classes is being erased automatically and when I load the class files it throws this:

My servlets class files are deleting/don't know where it goes.
This is my `web.xml` file inside `WEB-INF/` .classes mapped inside `web.xml` is in `WEB-INF/classes`. All class files inside this is getting erased.
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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"
version="3.0"
metadata-complete="true">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>HelloForm</servlet-name>
<servlet-class>HelloForm</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloForm</servlet-name>
<url-pattern>/HelloForm</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Upload</servlet-name>
<servlet-class>Upload</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Upload</servlet-name>
<url-pattern>/Upload</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Getapplicants</servlet-name>
<servlet-class>Getapplicants</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Getapplicants</servlet-name>
<url-pattern>/Getapplicants</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>First_round_selected</servlet-name>
<servlet-class>First_round_selected</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>First_round_selected</servlet-name>
<url-pattern>/First_round_selected</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Second_round_selected</servlet-name>
<servlet-class>Second_round_selected</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Second_round_selected</servlet-name>
<url-pattern>/Second_round_selected</url-pattern>
</servlet-mapping>
</web-app>
Stuck with this:
Upload.java:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
// Extend HttpServlet class
public class Upload extends HttpServlet {
// Method to handle GET method request.
public void doGet(HttpServletRequest request, HttpServletResponse
response)throws ServletException, IOException {
PrintWriter out = response.getWriter();
String first_name=request.getParameter("first_name");
String last_name=request.getParameter("last_name");
String email=request.getParameter("email");
String phone_number=request.getParameter("phone_number");
String experience =request.getParameter("experience");
try{
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/interview"
,"root","
");
Statement stmt=con.createStatement();
int rows=stmt.executeUpdate("insert into applicants
values('"+first_name+"','"+last_name+"','"+email+"',"+
Long.valueOf(phone_number
)+","+Integer.valueOf(experience)+")");
con.close();
out.print("Added Sucessfully");
}catch(Exception e){out.print(e);}
}
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
doGet(request, response);
}
}
Solution 1:[1]
As you said you are using tomcat 5 and it support till servlet 2.5. But you are using servlet 3.0
<web-app 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"
version="3.0"
see the details below
There are two solutions: Upgrade your tomcat or use servlet 2.5
Servlet 2.5 deployment descriptor
<web-app 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_2_5.xsd"
version="2.5">
</web-app>
Solution 2:[2]
try to put your servlet class to src/main/java folder. Also I recomend you to put it in package like com.servlet or something. Then in the web.xml fill the path to you class like this: package.MyServlet
Solution 3:[3]
If you are using compiling output to WEB-INF/classes then it erases this folder each time you compile the application. To fix this you should change the folder used for compiler output.
If you ever seen this guide How to Create a Dynamic Web Project in Eclipse then you will realize that output folder is created outside the web content.

(source: eclipse.org)
This allows to store/clean compiled files during development. Finally when you deploy your application to the server the content should be copied to WEB-INF/classes automatically.
Since class files are under WEB-INF folder they are not accessible from outside the web and you can safely browse the content.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vishnu T S |
| Solution 2 | Den B |
| Solution 3 | Glorfindel |

