Java Apache Tomcat 错误 http 状态 404
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24849700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache Tomcat error http status 404
提问by archit100994
To be honest i am a learner and this is my first ever servlet program. I made the basic servlet and intalled tomcat version 6 and even tomcat version 8. the server starts up correctly and i am able to see the tomcat start up page on going to
老实说,我是一个学习者,这是我的第一个 servlet 程序。我制作了基本的 servlet 并安装了 tomcat 版本 6 甚至 tomcat 版本 8。服务器正确启动,我能够看到 tomcat 启动页面
http://localhost:8080
but after logging to tomcat manager when i click on my folder name it gives me an error saying
但是在登录到 tomcat 管理器后,当我单击我的文件夹名称时,它给了我一个错误说
http status 404-/online/ (online is my folder created in webapps)
http status 404-/online/(在线是我在webapps中创建的文件夹)
type Status report
类型状态报告
message /online/
留言/在线/
description The requested resource is not available.
描述 请求的资源不可用。
here's my codes
这是我的代码
web.xml-> (in folder online->WEB-INF)
web.xml->(在文件夹 online->WEB-INF)
- <web-app>
- <servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
- <servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/FirstServlet</url-pattern>
</servlet-mapping>
</web-app>
FirstServlet.java->
FirstServlet.java->
import javax.servlet.*;
import java.io.*;
class FirstServelet implements Servlet
{
public void init(ServletConfig config)
{
}
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
{
PrintWriter out;
out=response.getWriter();
out.println("hello");
out.println("<html>");
out.println("<head>");
out.println("<title>MY First Servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<marquee>ban ja tar pls</marquee>");
out.println("</body>");
out.println("</html>");
}
public String getServletInfo()
{
return null;
}
public ServletConfig getServletConfig()
{
return null;
}
public void destroy ()
{
}
}
please resolve the 404 error
请解决404错误
回答by bitkot
The problem is you don't welcome-file-list
, I think the default page is index.html which I suppose is not there in you folder. You can provide any html or jsp file as default file but NOT a servlet as below.
问题是你没有welcome-file-list
,我认为默认页面是 index.html,我想它不在你的文件夹中。您可以提供任何 html 或 jsp 文件作为默认文件,但不能提供如下所示的 servlet。
<welcome-file-list>
<welcome-file>myfile.html</welcome-file>
</welcome-file-list>
You can access your servlet by hitting http://localhost:8080/online/FirstServlet
URL.
您可以通过点击http://localhost:8080/online/FirstServlet
URL来访问您的 servlet 。
You can create a default page which will redirect to FirstServlet i.e.
您可以创建一个默认页面,该页面将重定向到 FirstServlet 即
myfile.html
我的文件.html
<meta http-equiv="refresh" content="0; url=http://localhost:8080/online/FirstServlet" />
And also what @Braj said in the comment extend HttpServlet
instead of implement Servlet
.
还有@Braj 在评论中所说的,extend HttpServlet
而不是implement Servlet
.
Edit
编辑
You have a typo in servlet name. change the servlet name to FirstServlet
from FirstServelet
.
您在 servlet 名称中有一个拼写错误。将 servlet 名称更改为FirstServlet
from FirstServelet
。