java HTTP 状态 404,请求的资源不可用。我在做什么错误?雄猫6.0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17106213/
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
HTTP STATUS 404, requested resource is not available. What mistake am I doing? Tomcat 6.0
提问by Sai Krishna
My servlet application is
我的 servlet 应用程序是
package p1;
import javax.servlet.*;
import java.io.*;
public class MyServ extends GenericServlet{
public void init(ServletConfig con){
System.out.println("INIT");
}
public void service(ServletRequest req,ServletResponse res) throws ServletException,IOException{
PrintWriter pw=res.getWriter();
pw.println("HELLO");
pw.close();
}
}
and my web. xml file is
和我的网络。xml文件是
<web-app>
<servlet>
<servlet-name>sai</servlet-name>
<servlet-class>p1.MyServ</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sai</servlet-nsame>
<url-pattern>/abc</url-pattern>
</servlet-mapping>
</web-app>
I have pasted my WEB-INF folder into the webapp folder of tomcat 6.0. The WEB-INF folder has classes and web.xml file. classes folder has the package of my java program. When I try to run my servlet in the browser it shows
我已将我的 WEB-INF 文件夹粘贴到 tomcat 6.0 的 webapp 文件夹中。WEB-INF 文件夹包含类和 web.xml 文件。classes 文件夹中有我的 java 程序的包。当我尝试在浏览器中运行我的 servlet 时,它显示
HTTP Status 404 - type Status report message description The requested resource is not available.
HTTP 状态 404 - 类型 状态报告消息描述 请求的资源不可用。
Whats the mistake i am doing?
我在做什么错误?
回答by M.G.Manikandan
You must restart the server to apply web.xml changes. Make sure you have restarted the server.
您必须重新启动服务器才能应用 web.xml 更改。确保您已重新启动服务器。
回答by user1516873
don't copy WEB-INF in webapp forder. Create separate application folder, for example, test
and copy WEB-INT in test
Your servlet will be available on URL
不要在 webapp forder 中复制 WEB-INF。例如,创建单独的应用程序文件夹,test
并在test
您的 servlet 中复制 WEB-INT将在 URL 上可用
http://localhost:<port>/test/abc
<TOMCAT_HOME>
|-webapps
|-manager
|-data
|-docs
|-host-manager
|-ROOT
|_test <--- create this folser
|-WEB-INF
|-classes <--classes
|-lib <-- librares
|-web.xml
Also you can copy it in ROOT, in that case your servlet will be available on URL
您也可以在 ROOT 中复制它,在这种情况下,您的 servlet 将在 URL 上可用
http://localhost:<port>/abc
回答by shreyansh jogi
first check whether your tomcat sever is started by typing localhost:2020 if you get your tomcat page then its started
如果你得到你的 tomcat 页面,首先检查你的 tomcat 服务器是否通过输入 localhost:2020 启动然后它启动
回答by Yegoshin Maxim
You should paste to webapp/FirstApp folder. So Tomcat could provide the context for your application.
您应该粘贴到 webapp/FirstApp 文件夹。因此 Tomcat 可以为您的应用程序提供上下文。