0

while trying to run servlet encountering this error

Type Status Report

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/9.0.37 here is my .java

import java.sql.*;
class BatchUpdations
{
public static void main(String args[])
{
try
{
 Class.forName("com.mysql.cj.jdbc.Driver");
 Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/stud","root","root");
 Statement st=con.createStatement();
 st.addBatch("insert into student1 values(190,'sfd')");
 st.addBatch("insert into student1 values(193,'sasdf')");
 st.addBatch("insert into student1 values(590,'sadf')");
 st.addBatch("insert into student1 values(390,'adfd')");
 st.executeBatch();
 System.out.println("Records inserted");
 st.close();
 con.close();
}
 catch(Exception e)
 {
e.printStackTrace();
}
}
}

and web.xml

<servlet>
    <servlet-name>BatchUpdations</servlet-name>
    <servlet-class>BatchUpdations</servlet-class>
</servlet>
 <servlet-mapping>
    <servlet-name>BatchUpdations</servlet-name>
    <url-pattern>/BatchUpdations</url-pattern>
  </servlet-mapping>
<servlet>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
tvp
  • 1

1 Answers1

1

To me it seems, you didn't create a servlet at all. The code you shown is a standalone application, so no need for tomcat, no HTTP, no servlet. Just calling java -cp . BatchUpdations should start it. If you need it to be a web app, running inside tomcat, you would need to provide a servlet class and a complete jee webapplication structure (most of the time packaged inside a *.war file). A tutorial on how to do that, can be found here: https://www.tutorialspoint.com/servlets/servlets-first-example.htm

There are other ways to create a web application in Java, e.g. with Java configuration, or using Spring/Spring Boot or other frameworks. But the given one is the easiest to start with IMHO. In case you are eager to learn, what's all behind that I recommend reading the Servlet API specification. Latest version is 4.0 and available here: https://download.oracle.com/otndocs/jcp/servlet-4-final-eval-spec/index.html

Lars Opitz
  • 11
  • 1
  • 2
  • 2