0

First of all, I am aware that there are other questions regarding Tomcat, Eclipse, and the infamous 404 error. However, none of them manages to resolve the issue. I have spent well over 24 hours on this issue.

To save time, when I configured everything (including Tomcat, and creating a server in Eclipse), I:

• Changed the server location from "workspace metadata" to its correct location by using the "Switch Location" button located in the server's Properties window.

• I chose the "Use Tomcat Installation" option in Server Locations, and saved the choice I made.

In both cases, I restarted the server. If you're curious as to what app I'm currently working on, it's a simple Hello World app, found at: http://theopentutorials.com/examples/java-ee/servlet/how-to-create-a-servlet-with-eclipse-and-tomcat/

• I have included the Java file in the "welcome file" list inside web.xml.

Lastly, out of curiosity, why does the Eclipse browser only go to the project directory, and not the servlet itself? (If I add on the servlet name, then "Hello World" appears).

• Yes, if I enter "http://localhost:8080", the default Tomcat page appears, so no issues there.

Can anyone clue me in, as to why I am still getting 404s after all this, and following advice that has been marked as "Accepted" here at SO, such as the following:

HTTP Status 404 - The requested resource (/) is not available

Thanks in advance for any help, it is greatly appreciated.

Community
  • 1
  • 1
Paul
  • 95
  • 2
  • 12
  • You can check your deployed application out in the tomcat directory. It's usually located in `%PATH_TO_WORKSPACE%\ .metadata\.plugins\org.eclipse.wst.server.core\tmp%SERVER_NUMBER%`. Now just try to add something like `hello_world.htm` in your tomcat server in order to localize that 404. –  Mar 14 '15 at 05:42
  • Hi Dmitry, when you say "add something in your tomcat server", do you mean add it to the directory you mentioned? I am confused. – Paul Mar 14 '15 at 06:32
  • Yes, that's exactly what I meant. The directory that I mentioned is where eclipse contains your webapp for deploying. Sometimes it's diffucult to understand why exactly 404 error is occured. As you mentioned, there are tons of reasons for that and it might be useful to check out what with your webapp. –  Mar 14 '15 at 06:43

2 Answers2

1

The error 404 may occur because of large amount of different reasons. In order to resolve that, you should check your tomcat log file out first. It contains by the path:

%PATH_TO_WORKSPACE%\.metadata\.plugins\org.eclipse.wst.server.core\tmp%SERVER_NUMBER%\
logs

Usually it contains some stacktraces which discribes the problem. If not, then you should check your deployed application out there:

%PATH_TO_WORKSPACE%\.metadata\.plugins\org.eclipse.wst.server.core\
tmp%SERVER_NUMBER%\___YOUR_APP____

It might happen that your application was not deployed correctly by eclipse plugin (happens very often) and you should try this:

Project --> clean
'Right click on your server' --> clean

Or just remove your webapp from the directory I mentioned erlier and redeploy it from scratch.

0

There is something basic you need to understand regarding using tomcat(or application server for that matter). There is a slight difference between using from Eclipse and using from outside

Using From within Eclipse

What happens here is that Eclipse (by default) uses a copy of your tomcat installation and places it in its metadata workplace. This secondary tomcat is used by Eclipse for all deployments, re-deployments and all. Keep in mind that this is not your original copy of tomcat installation.

The difference in this tomcat installation is that is actually a minimal server, meaning that although it has all the deployment capabilities, it does not have some of the extra features that come with the tomcat installation and one main feature is the tomcat's homepage (the only reason why people out there get the infamous 404 resource not found when they try to run-on-server their application).

Workaround

Although not an issue (nor a bug from the Apache's end), you can still view your application by changing the URL to your application's url, homepage or no homepage ! All you have to do is change the url from http://localhost:8080 to http://localhost:8080/yourApplicationName and voila , the default page of your application will be shown that you mentioned in the welcome-page-list. Keep note that if you didn't specify a default page in your web.xml, you will again wind up with, yet again, the dreaded 404 resource not found page. The reason is that Tomcat has found your application, but it doesn't know what to do at the root context of your application. You can either map your servlet to the root of the application (that way it will always run at http://localhost:8080/yourApplicationName) or you can change the URL to the url-pattern that you mapped with the servlet in the web.xml, it must be something like http://localhost:8080/myApplicationName/myServletMappingPattern

Saif Asif
  • 5,516
  • 3
  • 31
  • 48
  • Hi Saif, thanks very much for the informative lesson. :) Can you please give me an example of what "myServletMappingPattern" (because it is a pattern), would look like? The name of my Project is HelloFormTwo, and the servlet's name is HelloFormTwoServlet. – Paul Mar 14 '15 at 06:52
  • What you need is a mapping url that you can access in the browser and which will tell the server to run your servlet on that URL. You must have defined a `url-pattern` inside the `web.xml` or if not that, then you can make use of the @WebServlet annotation defined by the Servlet3.0 specs. Patterns are usually like `/myServlet` or `/myTwoServlet` or `/FirstServletABC123` whatever you like – Saif Asif Mar 14 '15 at 07:09
  • My mapping URL is as follows: /HelloFormTwoServlet, yet it still gives me a 404 error. Would doing /HelloFormTwoServlet/* stop this from happening? – Paul Mar 14 '15 at 07:57
  • No, the url `/HelloFormTwoServlet` seems perfectly fine. I want you to first verify that the application you are running is getting deployed fine or not (check server logs). Next, based on the information you shared, the URL should be `http://localhost:8000/HelloFormTwo/HelloFromTwoServlet` and it should execute the doGet method in your servlet. Lastly, I want you to verify that there is no spelling mistake, I've noticed that your app name contains `Form` but your servlet name contains `from` – Saif Asif Mar 14 '15 at 10:07