gpt4 book ai didi

java - Http status 404 -/请求的资源不可用

转载 作者:行者123 更新时间:2023-11-28 23:56:36 29 4
gpt4 key购买 nike

<分区>

我是 java 的新手,我只是试图从部署描述文件 (web.xml) 中读取初始化参数,但出现上述错误?

我的 web.xml 和 java 文件编码在 snap 附件中。

我的目录结构是

c:\....tomcat\webapps\dd\web-inf\classes

java类文件没有错误。

enter image description here

编译成功的Java文件代码

import java.io.*; 
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet2 extends HttpServlet {

String fileName;
public void init(ServletConfig config) throws ServletException {
super.init(config);
fileName = config.getInitParameter("logfilename");
}

protected void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {
processRequest(request, response);
}

protected void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {
processRequest(request, response);
}

protected void processRequest(HttpServletRequest request,HttpServletResponse
response)throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println(fileName);
out.close();
}
}

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?> 
<web-app>
<servlet>
<servlet-name>MyServlet2</servlet-name>
<servlet-class>MyServlet2</servlet-class>
<init-param>
<param-name>logfilename</param-name>
<param-value>value1</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet2</servlet-name>
<url-pattern>/mc11</url-pattern>
</servlet-mapping>
</web-app>

我的目录和错误页面的其他细节我认为我的 web.xml 不工作 enter image description here

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