在Tomcat服务器上部署一个.war应用程序。

huangapple go评论78阅读模式
英文:

Deploying a .war application on a tomcat server

问题

我正在尝试在我的Tomcat服务器上部署我的hello.war文件(Java应用程序)。

起初,我是通过Tomcat默认页面上的“Manager App”来进行部署的,然后在应用程序部分显示出来(以下用红圈标出)。

enter image description here

但是,当我尝试通过点击该链接(https://ip-address/hello)来连接时,它会显示标准的“HTTP状态404 - 未找到”,并显示描述:“源服务器未找到目标资源的当前表示,或者不愿意透露存在目标资源。”(下图)

enter image description here

我甚至尝试将我的hello.war文件手动放入服务器的适当文件夹位置(“/opt/tomcat/apache-tomcat-9.0.33/webapps”),并在.war文件上添加了其他人的读取、执行权限,将用户“tomcat”添加为文件的所有者,然后重新启动服务。
但是仍然没有任何帮助,我仍然得到404错误。

英文:

I am trying to deploy my hello.war file (Java application) on my tomcat server.

At first I do it from the "Manager App" on tomcat's default page, and it shows off afterwards in the Applications section. (Attached below circled in red)

enter image description here

But when I try to connect to it by clicking on that link (https://ip-address/hello) it gives me a standard "HTTP Status 404 – Not Found" with the description: "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." (picture below)

enter image description here

I even try putting my hello.war file manually in the server in the appropriate folder location ("/opt/tomcat/apache-tomcat-9.0.33/webapps") and add read, execute permissions to 'others' on the .war file, add user 'tomcat' as the owner of the file, restart the service.
But still nothing seems to help and I still get that 404

答案1

得分: 1

这意味着在应用程序中您没有默认的起始页面。在WebContent下创建index.html并刷新页面。为了测试,您可以在index.html中放置任何内容,例如:

<html>
	<head>
		<title>Hello world</title>
	</head>
	<body>
		欢迎访问我的应用程序
	</body>
</html>

查看此链接以获取更多信息。

[更新]

--- 根据OP的另一个请求(请查看评论)发布以下更新 ---

正如我在评论中提到的,您需要将请求转发到一个JSP(例如queryResults.jsp),您希望在其中显示查询结果。将以下代码放在您的servlet的doGet方法末尾:

String nextJSP = "/queryResults.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request, response);

此代码将自动将请求转发到queryResults.jsp,您可以在其中访问保存在请求/会话对象中的查询结果。

如有任何疑问/问题,请随意在评论中提问。

英文:

It means you do not have a default start page in the application. Create index.html under WebContent and refresh the page. For testing, you can put any content in index.html e.g.

&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;Hello world&lt;/title&gt;
	&lt;/head&gt;
	&lt;body&gt;
		Welcome to my application
	&lt;/body&gt;
&lt;/html&gt;

Check this to learn more about it.

[Update]

--- Posting the following update based on another request (check comments) from OP ---

As I have mentioned in the comment, you need to forward the request to a JSP (e.g. queryResults.jsp) where you want to show the query result. Put the following code at the end in the doGet method of your servlet:

String nextJSP = &quot;/queryResults.jsp&quot;;
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request,response);

This code will automatically forward the request to queryResults.jsp where you can access the query result saved in the request/session object.

Feel free to comment in case of any doubt/issue.

huangapple
  • 本文由 发表于 2020年4月6日 15:38:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/61054997.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定