Docker Tomcat Container在运行servlet时出现404错误

eoxn13cs  于 5个月前  发布在  Docker
关注(0)|答案(1)|浏览(68)

当我运行使用我的应用程序的war文件构建的Docker容器时,我得到了这个错误:
第一个月
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
我使用的URL是http://<public DNS of my linux machine>:8085/
http://ec2-18-188-198-18.us-east-2.compute.amazonaws.com:8085
Linux计算机是从Linux AMI创建的AWS EC2示例
我在这台机器上运行Docker。
这是我使用docker ps

获得的Docker容器端口详细信息
这是我的Dockerfile

FROM tomcat:9
COPY app.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD ["/usr/local/tomcat/bin/catalina.sh", "run"]

字符串
下面是我的一个servlet文件,作为对在其余文件中使用的Java代码类型的引用

import java.io.IOException;
import java.io.PrintWriter;

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 javax.servlet.http.HttpSession;
@WebServlet("/")
public class AdminLogin extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html");


正如您所看到的,我在代码中使用的是javax.servlets.* 而不是jakarta.servlets。
通常情况下,如果我使用tomcat10,但我使用的是tomcat9和javax.servlets.*,就会出现这个问题。
所以我不知道如何解决这个问题。

mklgxw1f

mklgxw1f1#

我能够通过修改Dockerfile和被命中的URL来解决这个问题。
这是新的Dockerfile

FROM tomcat:9.0-jdk11
RUN cp -r $CATALINA_HOME/webapps.dist/* $CATALINA_HOME/webapps
COPY app.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD ["/usr/local/tomcat/bin/catalina.sh", "run"]

字符串
新的URL:http://<public DNS of my linux machine>:8085/<name of war file>
http://ec2-18-188-198-18.us-east-2.compute.amazonaws.com:8085/app

相关问题