HTTP状态404 - 在使用Tomcat的Eclipse上 [英] HTTP Status 404 - on Eclipse with Tomcat
问题描述
我正在尝试使用Eclipse在我的本地Tomcat上运行一个servlet。
但是我不断收到此错误,不知道该做什么。
我实际上记录在这里: http://www.screenr.com/ZyD8
非常感谢!
此外,我将web.xml更改为:
<?xml version =1.0encoding =UTF-8?>
< web-app xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xmlns:web =http://java.sun.com/xml /ns/javaee/web-app_2_5.xsd
id =WebApp_ID
version =3.0
xmlns =http://java.sun.com/xml/ns/ javaee
xsi:schemaLocation =http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd>
< display-name>
TEST3
< / display-name>
< welcome-file-list>
< welcome-file>
TEST3
< / welcome-file>
< / welcome-file-list>
< servlet>
< servlet-name>
helloServlet
< / servlet-name>
< servlet-class>
HelloServlet
< / servlet-class>
< / servlet>
< servlet-mapping>
< servlet-name>
helloServlet
< / servlet-name>
< url-pattern>
/ hello
< / url-pattern>
< / servlet-mapping>
< / web-app>
我看过你的链接。 b
$ b
当您运行任何动态Web项目时。默认情况下, Servlet
容器(在这种情况下为Tomcat)将搜索在欢迎列表中指定的文件。检查您的 web.xml
,它应该包含条目,如
欢迎-文件列表>
< welcome-file> index.html< / welcome-file>
< welcome-file> index.htm< / welcome-file>
< welcome-file> index.jsp< / welcome-file>
< welcome-file> default.html< / welcome-file>
< welcome-file> default.htm< / welcome-file>
< welcome-file> default.jsp< / welcome-file>
< / welcome-file-list>
您没有从上述列表中创建任何文件。所以,运行
http:// localhost:8080 / TEST2
会给你404错误。
相反运行: http:// localhost:8080 / TEST2 / HelloSerlvet
将调用您创建的servlet。
编辑:检查eclipse的项目菜单并检查自动构建,并运行Servlet容器( http:// localhost:8080
)。
编辑2:右键单击项目 - >属性,选择Java构建路径 - >源选项卡 - >更改默认输出文件夹。 / WebContent
(eclipse中的默认值)创建 / WEB-INF / classes
I am trying just to run a servlet on my local Tomcat with Eclipse.
But I keep getting this error and do not have any idea what to do differently.
I actually recorded it here : http://www.screenr.com/ZyD8
Many thanks!
Also I changed the web.xml to this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" >
<display-name>
TEST3
</display-name>
<welcome-file-list>
<welcome-file>
TEST3
</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>
helloServlet
</servlet-name>
<servlet-class>
HelloServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
helloServlet
</servlet-name>
<url-pattern>
/hello
</url-pattern>
</servlet-mapping>
</web-app>
I have seen your link.
When ever you run any dynamic web project. By default Servlet
container (which is Tomcat in this case) searches for files specified in wel-come list. Check your web.xml
, it should contains entry like
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
You haven't created file from any of the above list. So, running
http://localhost:8080/TEST2
will give you 404 error.
Rather run : http://localhost:8080/TEST2/HelloSerlvet
will invoke the servlet which you have created.
Edit: Check Project Menu of eclipse and verify "Build Automatically" is checked and Servlet container is running (http://localhost:8080
).
Edit 2: Right Click Project --> Properties, Select Java Build Path --> source Tab --> Change Default output folder. Create /WEB-INF/classes
under /WebContent
(default in eclipse)
这篇关于HTTP状态404 - 在使用Tomcat的Eclipse上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!