我正在尝试使用仅连接到 mssql 服务器的 Maven 创建一个简单的 Web 应用程序,我的 IDE 是 IntelliJ。这是我的 index.jsp 文件:
<%@ page import="java.io.IOException" %>
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection connection =
DriverManager.getConnection("jdbc:sqlServer://127.0.0.1;
databaseName=database password=passwordd");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select * from tablo
where id = 10");
while(resultSet.next()){
out.println(resultSet.getArray(0) + " " + resultSet.getArray(1));
}
}catch(IOException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}catch(ClassNotFoundException e){
e.printStackTrace();
}
%>
</body>
</html>
我没有更改 web.xml 文件,所以它只是空的。我的问题是,当我在 tomcat 服务器上运行 Web 应用程序时,出现 HTTP Status 404 - Not Found 错误。 URL 是 “http://localhost:8080/”
。我也试过 http://localhost:8080/index.jsp
和 "http://localhost:8080/webapp/index.jsp"
但结果是一样的。感觉我没有提供足够的信息,这只是因为我是创建 Web 应用程序的新手。我哪里做错了?
编辑:
我只是改变了我部署网络项目和工作的方式。之前是mywebapp: war
,现在mywebapp: war exploded
。为什么它现在起作用了?它们或指向我的项目文件夹有什么区别? –
最佳答案
我的问题是我部署网络项目的方式。当我将其部署为 MyWebApp: war exploded
时,它运行良好。希望它能对某人有所帮助。
关于java - 为什么无法访问我的 Web 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48448013/