gpt4 book ai didi

java - 404 请求的资源不可用 Eclipse/Tomcat

转载 作者:行者123 更新时间:2023-11-30 10:44:07 25 4
gpt4 key购买 nike

<分区>

到目前为止,我想我已经阅读了关于这个主题的所有问题,并且我确实尝试了很多解决方案,如果我遗漏了什么,我深表歉意。我在 Tomcat 8 中使用 Eclipse。Tomcat 已配置为服务器,MySQL 连接器....jar 位于 WEB-INF/lib 文件夹中,web.xml 位于/WEB-INF 文件夹中,索引位于/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

开始.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>

现在,每当我在服务器上运行 index.html 时,一切正常,但是在按下按钮后它指定了 404 错误,我不知道为什么会发生这种情况。我已经尝试在 index.html 中仅使用/Start 作为操作,这导致错误消息仅指向/Start,但是当我使用 Servlets/Start 时它指向 Servlets/Servlets/Start 如果有帮助的话。输入 localhost:8080/Servlets 提示我到 index.html 然后导致同样的问题

由于我慢慢变得非常沮丧,所以我想向您寻求帮助,在此先感谢您!

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com