在 tomcat 服务器上部署 .war 应用程序
Deploying a .war application on a tomcat server
我正在尝试在我的 tomcat 服务器上部署我的 hello.war 文件(Java 应用程序)。
起初我是从 tomcat 的默认页面上的 "Manager App" 开始的,它显示在 wards 之后的“应用程序”部分。 (附下红圈)
enter image description here
但是当我尝试通过单击 link (https://ip-address/hello) 连接到它时,它会给我一个标准的 "HTTP Status 404 – Not Found" 和描述:"The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."(图片下)
enter image description here
我什至尝试将我的 hello.war 文件手动放入服务器中适当的文件夹位置(/opt/tomcat/apache-tomcat-9.0.33/webapps)并添加对 'others' 的读取、执行权限在 .war 文件上,将用户 'tomcat' 添加为文件的所有者,重新启动服务。
但似乎仍然没有任何帮助,我仍然得到 404
这意味着您的应用程序中没有默认起始页。在 WebContent
下创建 index.html
并刷新页面。为了测试,您可以将任何内容放入 index.html
例如
<html>
<head>
<title>Hello world</title>
</head>
<body>
Welcome to my application
</body>
</html>
查看 this 以了解更多信息。
[更新]
--- 根据来自 OP 的另一个请求(检查评论)发布以下更新 ---
正如我在评论中提到的,您需要将请求转发到 JSP(例如 queryResults.jsp)查询结果。将以下代码放在 servlet 的 doGet
方法的末尾:
String nextJSP = "/queryResults.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request,response);
此代码会自动将请求转发到 queryResults.jsp
,您可以在其中访问保存在 request/session 对象中的查询结果。
如有任何问题,请随时发表评论 doubt/issue。
我正在尝试在我的 tomcat 服务器上部署我的 hello.war 文件(Java 应用程序)。
起初我是从 tomcat 的默认页面上的 "Manager App" 开始的,它显示在 wards 之后的“应用程序”部分。 (附下红圈)
enter image description here
但是当我尝试通过单击 link (https://ip-address/hello) 连接到它时,它会给我一个标准的 "HTTP Status 404 – Not Found" 和描述:"The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."(图片下)
enter image description here
我什至尝试将我的 hello.war 文件手动放入服务器中适当的文件夹位置(/opt/tomcat/apache-tomcat-9.0.33/webapps)并添加对 'others' 的读取、执行权限在 .war 文件上,将用户 'tomcat' 添加为文件的所有者,重新启动服务。 但似乎仍然没有任何帮助,我仍然得到 404
这意味着您的应用程序中没有默认起始页。在 WebContent
下创建 index.html
并刷新页面。为了测试,您可以将任何内容放入 index.html
例如
<html>
<head>
<title>Hello world</title>
</head>
<body>
Welcome to my application
</body>
</html>
查看 this 以了解更多信息。
[更新]
--- 根据来自 OP 的另一个请求(检查评论)发布以下更新 ---
正如我在评论中提到的,您需要将请求转发到 JSP(例如 queryResults.jsp)查询结果。将以下代码放在 servlet 的 doGet
方法的末尾:
String nextJSP = "/queryResults.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request,response);
此代码会自动将请求转发到 queryResults.jsp
,您可以在其中访问保存在 request/session 对象中的查询结果。
如有任何问题,请随时发表评论 doubt/issue。