5

I'm trying to create a very basic web project called "web" using MyEclipse and JBoss 5 as an application server. I've created one package called "pages" and inside it one servlet called "UserInterface". The problem is when I deploy the project and run the server I always get the error report: HTTP Status 404 - Servlet is not available.

This is a part of my web.xml:

<servlet>
    <servlet-name>UserInterface</servlet-name>
    <servlet-class>pages.UserInterface</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>UserInterface</servlet-name>
    <url-pattern>/UserInterface</url-pattern>
  </servlet-mapping>

and I'm navigating in the browser to: http://localhost:8080/web/UserInterface

What am I doing wrong here?

Thanks

NadaNK
  • 782
  • 2
  • 10
  • 26

3 Answers3

5

404 means the URL you're trying to access does not point to an existing resource on your server. Check the address again, maybe the "web" (from http://localhost:8080/web/UserInterface) part is not correct because maybe the app is not deployed with that name. By default the app context name is derrived from the filename of the ".war" file such as if your file is "myApp.war", your app should be available at http://localhost:8080/myApp

Also, if you're actually deploying your war inside an .ear file that that ear file will contain an application.xml aplpication descriptor which can map your app file to a specific context, no-matter what the .war filename is, something like:

<module>
    <web>
      <web-uri>myApp.war</web-uri>
      <context-root>theApp</context-root>
    </web>
  </module>

Finally, if you're autodeploying from Eclipse with the JBoss Eclipse connector, sometimes the thing bugs out and doesn't in fact deploy your app properly (even though the app itself is fine). If that's the case, trying manually deploying the .war to an application server and check it that way.

Shivan Dragon
  • 15,004
  • 9
  • 62
  • 103
2

HTTP Status 404 - Servlet is not available.

The loading of the servlet has failed (if the servlet wasn't properly declared in web.xml or the URL was wrong, then you should instead have seen "404 - Resource not found"). Simply put, the <servlet-class> is wrong or the concrete class file isn't present in /WEB-INF/classes.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • @Andrei: only when thrown by `service()`, `doGet()` and so on. But in this case the servlet is simply not available at all. The container is aware of the servlet URL mapping, but doesn't have a valid working instance at hands, because instantiation/initialization has failed. – BalusC Nov 24 '11 at 12:45
  • Hm, yeah but I'm quite sure from my own crappy coding that if I, for example have a servlet with an init() overriden method that throws a NPE, then accessing that servlet (in Jetty for example) will return an HTTP 500. – Shivan Dragon Nov 24 '11 at 12:48
  • @Andrei: OP is using JBoss, not Jetty. – BalusC Nov 24 '11 at 12:49
  • BalusC, this is how the servlet specs work. 404 is bad URL, 500 is when the URL is infact mapped to a servlet but that servlet can't return a response due to error/exception. The person asking this question can check his code all he/she wants, if it's not the right url he's typing in, he'll get an 404 even with a perfectlly working servlet. – Shivan Dragon Nov 24 '11 at 12:59
  • 1
    BalusC: Make a webApp with a servlet. Throw an exception in either the constructor or the init() method. Deploy that to JBoss AS. Access your servlet's URL. Then access a non existing URL. See when you get HTTP 404 and when you get HTTP 500. – Shivan Dragon Nov 24 '11 at 13:16
  • @Andrei: You're right, OP's problem is not caused by an exception in init, but by the class not being found. The URL is however definitely correct and matched the servlet mapping. – BalusC Nov 24 '11 at 13:22
  • +1, that's something I would've never thought of. In this case the web-app would not be deployed at all, thus returning 404's for an URL that's actually mapped to a servlet. – Shivan Dragon Nov 24 '11 at 13:31
  • @Andrei: The web app **is** deployed, all working servlets are available, only the servlets which failed to load are unavailable. I was able to reproduce the same on Tomcat btw (always thought it was JBoss specific). – BalusC Nov 24 '11 at 13:43
  • Yes, you're right. I've tried it with the latest JBoss (version 7-beta). With this one I get deployment "class not found" error. With older versions this is not the case (app get's deployed, error when accessing the servlet). – Shivan Dragon Nov 24 '11 at 13:49
2

I still dont know what was wrong, but I've created another servlet called user, and in the web.xml I've added /servlet before the class and navigated to it in the browser (http://localhost:8080/web/servlet/User) and it worked.

<servlet>
    <servlet-name>User</servlet-name>
    <servlet-class>pages.User</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>User</servlet-name>
    <url-pattern>/servlet/User</url-pattern>
  </servlet-mapping>

Thanks everyone for your help!

NadaNK
  • 782
  • 2
  • 10
  • 26