I think I've read every question on this topic so far and I really tried a lot of solutions, so sorry if I overlooked anything. I'm using Eclipse with Tomcat 8. Tomcat is already configured as server and the MySQL-connector....jar is in the WEB-INF/lib folder, web.xml just in the /WEB-INF one and the index just in /WebContent
index.html:
<!DOCTYPE html>
<html>
<form action="Servlets/Start" method="post">
<font face="verdana" size="2">
Enter Table Name :<input type="text" name="table">
<input type="submit" value="Display">
</font>
</form>
</html
start.java:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/**
* Servlet implementation class Start
*/
@WebServlet("/Start")
public class Start extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Start() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse respond) throws ServletException, IOException {
PrintWriter pw=respond.getWriter();
respond.SetContentType("text/html");
String tb=request.getParameter("table");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc::oracle::thin:@localhost:music","root","1234");
Statement st=con.createStatement();
System.out.println("connection established successfully!");
ResultSet rs=st.executeQuery("SELECT * FROM"+tb);
pw.println("<table border=1>");
while(rs.next())
{
pw.println("<tr><td>"+rs.getInt(1)+"</td></td>+rs.getString(2)+</td>"+"<td>"+rs.getString(3)+"</td></tr>");
}
pw.println("</table>");
pw.close();
}
catch (Exception e){
e.printStackTrace();
}
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>Servlets</display-name>
<servlet>
<servlet-name>Start</servlet-name>
<servlet-class>start.Start</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Start</servlet-name>
<url-pattern>/Start</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
Now whenever I run the index.html on the server, everything works fine, however after pressing the button it specifies a 404 Error and I have no idea why exactly this occurs. I've tried using just /Start as action in index.html, which leads to the error message just pointing to /Start, however when I use Servlets/Start it is pointing to Servlets/Servlets/Start if that helps. Entering localhost:8080/Servlets prompts me to index.html which then leads to the same problem
As I'm slowly getting very frustrated, I'd like to ask you for help, thanks in advance!