无法运行我的servlet-错误404 [英] Cannot run my servlet - Error 404

查看:250
本文介绍了无法运行我的servlet-错误404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次制作仅显示text/html的Servlet程序的尝试.我按原样创建了目录-

This is my first attempt at making a Servlet Program which just displays text/html. I created the directories as is should be -

C:\ Java_Advanced \ DemoServlet

C:\Java_Advanced\DemoServlet

DemoServlet(文件夹) --WEB-INF ---- classes(包含我的.class文件) ---- lib ---- web.xml --MyServlet.java(与WEB-INF并行坐在) 我正在使用Tomcat 8.0.9 这是我的web.xml-

DemoServlet (folder) --WEB-INF ----classes (containing my .class file) ----lib ----web.xml --MyServlet.java (sitting in parallel with WEB-INF) I'm using tomcat apache 8.0.9 Here is my web.xml -

<web-app>
<servlet>
    <servlet-name>Hi</servlet-name>
    <servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Hi</servlet-name>
    <url-pattern>/run</url-pattern>
</servlet-mapping>
</web-app>

我制作了DemoServlet内部内容的war文件(demo.war). 我启动了Tomcat Apache服务.我给了端口号,而不是默认的8080.我成功部署了demo.war(我想是因为在上面打印了OK消息,并且应用程序/demo的Running正在变为 true (我有人告诉您状态为true表示xml文件没有问题)).

I made the war file (demo.war) of whatever was inside the DemoServlet. I started the Tomcat Apache service. I have given a port number other than the default 8080. I deployed my demo.war successfully (I am assuming because the message OK was printed above AND the application /demo's Running is coming to be true(I am told that a true state means there is no problem with the xml file)).

但仍然我打开浏览器的新选项卡/窗口,然后键入"localhost:myportnumber/demo/run",我得到的只是HTTP Status Error 404描述:请求的资源不可用.我尝试使用ctrl + F5刷新,尝试使用不同的浏览器,但仍然给出相同的错误.

But still I open the new tab/window of the browser and type "localhost:myportnumber/demo/run" and all I get is HTTP Status Error 404 description: The requested resource is not available. I have tried refreshing with ctrl+F5, tried different browsers but still gives the same error.

这是怎么了?我通过互联网搜索,在此网站上找到了一些东西: http://www.ntu.edu.sg/home /ehchua/programming/howto/Tomcat_HowTo.html#TomcatDebug

What is wrong here? I searched over the internet and found something on this site: http://www.ntu.edu.sg/home/ehchua/programming/howto/Tomcat_HowTo.html#TomcatDebug

(一直滚动到显示错误404的底部) 一切都很好,直到3.d点.在我的情况下,提到为xxxx的子目录是"demo",对吗?它确实存在. demo.war与之并排放置(这应该是吗?)

(Scroll all the way to the bottom where it says for error 404) Everything is fine until 3.d point. The sub-directory mentioned as xxxx is "demo" in my case right? It does exist. And so does demo.war alongside it in parallel(is that how it should be?)

C:\ Program Files \ Apache Software Foundation \ Tomcat 8.0 \ webapps \ demo

C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps\demo

C:\ Program Files \ Apache Software Foundation \ Tomcat 8.0 \ webapps \ demo.war

C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps\demo.war

当我打开演示目录时,我没有得到WEB-INF子目录.而是有一个META-INF子目录,其旁边是MyServlet.java文件.打开META-INF文件夹,有一个MANIFEST.MF文件.现在那是什么?那么,这就是获取404的原因.即使这是我如何解决的问题?

When I open the demo directory I DO NOT get a WEB-INF sub-directory. Instead there is a META-INF sub-directory and alongside it MyServlet.java file. Opening the META-INF folder there is a MANIFEST.MF file. Now what is that?? So, is this the reason for getting 404. Even if it is how do I fix it?

推荐答案

您的war文件的构造函数似乎错误.

It looks as if the structor of your war file is wrong.

战争文件的内部至少应该看起来像:

The inside of the war file should at least look like:

WEB-INF/web.xml
WEB-INF/classes/MyServlet.class

查看您的战争文件.这只是一个zip文件.

Look in your war file. It is just a zip file.

这篇关于无法运行我的servlet-错误404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆