When I am trying to run a servlet in which I am just establishing a general Database Connection it shows me this error
HTTP Status 404 – Not Found
Type Status Report
Message The requested resource [/Setting_Up_JNDI/Demo] is not available
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.52
Even though I have the file in my project. Please have a look at my servlet
@WebServlet("/Demo")
public class Demo extends HttpServlet {
private static final long serialVersionUID = 1L;
private DataSource dataSource;
@Resource(name="jdbc/project")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out=response.getWriter();
java.sql.Connection connect=null;
java.sql.Statement stmt=null;
ResultSet rs=null;
try {
connect = dataSource.getConnection();
String query ="Select * from users";
stmt=connect.createStatement();
rs=stmt.executeQuery(query);
while(rs.next()) {
out.print("</br>"+ rs.getString("email"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Here is my contex.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/project"
auth="Container"
type="javax.sql.DataSource"
username="saboor"
password="baba2011"
driverClassName="com.mysql.cj.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/saboor_db?useSSL=false"
maxActive="25"
maxIdle="5"/>
</Context>
Even though I have the required files in my orject structure the strange error keeps popping up. P.S I can't access http://localhost:8080/ Here is my project structure