JBoss error report: HTTP Status 404 - Servlet is not available
Asked Answered
C

3

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

Caine answered 24/11, 2011 at 5:23 Comment(5)
A listing of the files in the deployed web app would be useful. Are you deploying it as a .war?Tull
also is the project deployed with the context path = web? can you access the root localhost:8080/web?Owings
When the server starts or application is getting deployed, do you see any problems in the logs or console output ?Cramp
Yes localhost:8080/web opens the index page with no problems and @Santosh, no I've watched it carefully, no exceptions or whateverCaine
Just clear the cookies.. it will workHerophilus
C
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!

Caine answered 25/11, 2011 at 16:28 Comment(0)
S
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.

Sexagesimal answered 24/11, 2011 at 12:41 Comment(0)
R
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.

Rebellion answered 24/11, 2011 at 12:27 Comment(9)
@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.Rebellion
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.Sexagesimal
@Andrei: OP is using JBoss, not Jetty.Rebellion
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.Sexagesimal
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.Sexagesimal
@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.Rebellion
+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.Sexagesimal
@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).Rebellion
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).Sexagesimal
C
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!

Caine answered 25/11, 2011 at 16:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.