HTTP STATUS 404, requested resource is not available. What mistake am I doing? Tomcat 6.0

走远了吗. 提交于 2020-01-14 06:09:27

问题


My servlet application is

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

<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

HTTP Status 404 - type Status report message description The requested resource is not available.

Whats the mistake i am doing?


回答1:


You must restart the server to apply web.xml changes. Make sure you have restarted the server.




回答2:


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

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

http://localhost:<port>/abc



回答3:


You should paste to webapp/FirstApp folder. So Tomcat could provide the context for your application.




回答4:


first check whether your tomcat sever is started by typing localhost:2020 if you get your tomcat page then its started



来源:https://stackoverflow.com/questions/17106213/http-status-404-requested-resource-is-not-available-what-mistake-am-i-doing-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!