This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Spring and the fly likes Problem finding index page under WEB-INF / Spring MVC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Problem finding index page under WEB-INF / Spring MVC" Watch "Problem finding index page under WEB-INF / Spring MVC" New topic
Author

Problem finding index page under WEB-INF / Spring MVC

Mike Gibbs
Greenhorn

Joined: Oct 31, 2011
Posts: 11
I'm trying to move all my jsps into a folder under WebContents/WEB-INF/view but I keep getting a 404. Going to http://localhost:8080/test-app/ doesn't find my index.jsp under the view folder, but is ok in the WebContent folder. Why might this be?

Folder structure:


dispatcher-servlet.xml



web.xml

Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

You should try...
http://localhost:8080/test-app/index it won't find an index.jsp file if you are only pointing at the root...

Sean


I love this place!
Mike Gibbs
Greenhorn

Joined: Oct 31, 2011
Posts: 11
Sean Clark wrote:Hey,

You should try...
http://localhost:8080/test-app/index it won't find an index.jsp file if you are only pointing at the root...

Sean


That doesn't work either.
Mike Gibbs
Greenhorn

Joined: Oct 31, 2011
Posts: 11
Ah, folders under WEB-INF are protected and must be accessed via code.

http://stackoverflow.com/questions/4688841/http-404-problem-jsp-can-not-see-in-web
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

That shouldn't matter, that's why you have created a viewResolver in your spring configuration and why you have used the <mvc:view-controller /> annotation.
There is however another problem in your configuration that is probably the issue, you have not created Spring's servlet in the web.xml you posted. Therefore Spring will never be initialised.

Sean
Mike Gibbs
Greenhorn

Joined: Oct 31, 2011
Posts: 11
Sean Clark wrote:Hey,

That shouldn't matter, that's why you have created a viewResolver in your spring configuration and why you have used the <mvc:view-controller /> annotation.
There is however another problem in your configuration that is probably the issue, you have not created Spring's servlet in the web.xml you posted. Therefore Spring will never be initialised.

Sean


Hey,

I appreciate your help, I updated my code in the first post.

<mvc:view-controller /> - I use this tag because I used this on placement this summer, and I thought I'd use it again, but I can't seem to set up the application properly with Tomcat, before, I was using Google App Engine.

If I go to my index.jsp by going to http://localhost:8080/test-app/ I get a 404 (Going to http://localhost:8080/ gets me the Tomcat management page).
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

The URL pattern for the servlet is still wrong, it should go from the context root (test-app) so it should be /*.

Sean
Mike Gibbs
Greenhorn

Joined: Oct 31, 2011
Posts: 11
Sean Clark wrote:Hey,

The URL pattern for the servlet is still wrong, it should go from the context root (test-app) so it should be /*.

Sean


Still doesn't work.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Ok got it, should be / and not /*.

I just created a test app with your settings (apart from the sitemesh filter which I commented out and the listener which I did the same as it expects an applicationContext.xml file).

Sean
Mike Gibbs
Greenhorn

Joined: Oct 31, 2011
Posts: 11
Sean Clark wrote:Ok got it, should be / and not /*.

I just created a test app with your settings (apart from the sitemesh filter which I commented out and the listener which I did the same as it expects an applicationContext.xml file).

Sean


Tried / and not /*, and commented out the sitemesh, restarted the server too. I'm using Tomcat 7, using the Tomcat installaion in Eclipse.

Edit:
Can you upload your test app for me to test please?
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

What url are you using?

Sean
Mike Gibbs
Greenhorn

Joined: Oct 31, 2011
Posts: 11
Sean Clark wrote:What url are you using?

Sean


http://localhost:8080/test-app/
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

I'm out of ideas then, it's certainly working from mine.
Just make sure there are no errors coming up when tomcat starts.

Sorry.
Sean
Mike Gibbs
Greenhorn

Joined: Oct 31, 2011
Posts: 11
Problem solved.
Mike Gibbs
Greenhorn

Joined: Oct 31, 2011
Posts: 11
Problem solved.
sunny sand
Greenhorn

Joined: Mar 30, 2013
Posts: 4
Can we use mvc:view-controller tag for displaying a tiles view.
Eg:If we have a tiles definition of the form <definition name="userLogon.page" template="webapp/app/layout/baseLayoutExterior.jsp" extends="basePageDefinition">
Can we write <mvc:view-controller path="/logon" view-name="userLogon.page"/> in our servlet.xml file.
I am getting an HTTP 404 RESOURCE NOT FOUND ERROR on this whereas a normal hello.jsp page is displayed without problems.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem finding index page under WEB-INF / Spring MVC