1

I am getting a 404 error: The requested resource is not available in a spring mvc application that I am developing in eclipse and testing on a local instance of tomcat 7 using run as ... run on server from within eclipse. The error shows up when the application launches the root url of the app.

I have not made changes to welcome.jsp, or to the xml config files since it worked last. Since the problem is NOT with the config files, I am not distracting this posting by adding them.

Also note that there is no error log or stack trace in the eclipse console.

How can I get my app to load without throwing this 404?

NOTE: I am putting my own answer below. It turns out the solution was to right click on the server instance in the servers tab in eclipse, then do a clean, then publish, then run as...run on server again, which caused the app to load with a meaningful stack trace, which I then resolved easily. As I predicted above, this problem was with eclipse, it was not with the config files. This is a valid question. There was no need to downvote it or to vote to close it. I hope it helps others.

CodeMed
  • 9,527
  • 70
  • 212
  • 364

3 Answers3

1

Ordinarily you don't put your html or jsp files under the WEB-INF folder. Usually your directory structure looks something like this:

[application root]
 |
 |_ index.html
 |_ index.jsp
 |_ media
 |    |_ css
 |    |_ js
 |    |    |_ jquery..js
 |    |    
 |    |_ images
 |_ META-INF
 |        |_ context.xml
 |_WEB-INF
         |_ classes
         |_ lib
         |    |_ jed-1.0.jar
         |    |_ gson-2.2.4.jar
         |    |_ log4j-1.2.8.jar
         |    |_ mysql-connector-java-5.1.18.jar
         |_ properties
             |_ log4j_CONSOLE.properties
             |_ log4j_FILE.properties

You will get a 404 error because the servlet container is looking for html or jsp pages under the application root folder, not under the WEB-INF folder. In addition, your web.xml file should contain something like the following to specifically point to the home page:

<welcome-file-list>
   <welcome-file>index.jsp</welcome-file>    
</welcome-file-list>

Your web.xml doesn't have this. Hope this helps.

Alan
  • 822
  • 1
  • 16
  • 39
  • @Alan That is not true, you could use the "view resolver" to put you views within WEB-INF, that is something really common, I think is for some security reasons (I don't remember). – jenaiz Mar 18 '14 at 20:02
  • As I was thinking: http://stackoverflow.com/questions/6825907/why-put-jsp-in-web-inf – jenaiz Mar 18 '14 at 20:13
  • @Alan +1 I figured out the solution and posted it as another answer if you are interested. Thank you again for trying to help. I very much appreciate your time. – CodeMed Mar 18 '14 at 22:35
1

EDIT ( I have removed the part with the viewResolver setup)

I recommend you one of these ideas:

  • Check the setup with your tomcat within eclipse and check that your changes are published in tomcat correctly

  • Go to the properties of your project and check the "Deployment Assembly" and check that the folders that you see there are ok, somethings eclipse delete some paths here or don't link with the right "deploy path", you can add more or edit

  • And the last one :). "Play a little" with the tomcat menu. Sometimes for me it works, to clean the server, or restart or the biggest one: remove the web-app, clean, restart the tomcat to be sure that the app is not restarting (somethings the clean doesn't work perfectly) and add the app again.

I hope some of those things in order. (Without to see the setup or check some things within your eclipse is difficult to imagine more)

jenaiz
  • 547
  • 2
  • 15
  • @CodeMed How do you deploy the app with eclipse? Exploded or not-exploded? Are you sure that you eclipse deployment is finding the jsp files? It could be that your deployment with eclipse was doing something bad and that is the reason why it couldn't find the file. – jenaiz Mar 18 '14 at 20:18
  • +1 for trying to look deeper into this. I will try your new suggestions now. I just tried your ViewResolver changes and eclipse is giving me an error that tomcat 7 failed to start, which may not be related to your suggestion because I was getting that error recently. I think something changed in my setup, either elsewhere in my app, or in tomcat. I am just not sure what or where to look. Will try your new ideas now. – CodeMed Mar 18 '14 at 20:48
  • I figured out the solution and posted it as another answer if you are interested. Thank you again for trying to help. I very much appreciate your time. If I could +2, I would. – CodeMed Mar 18 '14 at 22:35
1

The problem was with corruption in Eclipse. So the solution was:

  1. click on servers tab in eclipse
  2. right click on the server instance
  3. choose clean
  4. repeat right click on server instance then choose publish
  5. do run as...run on server for the app

These 5 steps resulted in the app loading with a meaningful stack trace error, which involved redundant url mapping in _someclassname_controller.java that I was in the process of editing when I last worked in Eclipse. When I resolved that stack trace error, the app ran again.

bluish
  • 26,356
  • 27
  • 122
  • 180
CodeMed
  • 9,527
  • 70
  • 212
  • 364