简体   繁体   中英

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

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?

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

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

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

首先检查你的tomcat服务器是否通过键入localhost:2020来启动,如果你得到tomcat页面然后启动它

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM