aspose file tools*
The moose likes Spring and the fly likes Spring 3 MVC Controller Not Returning Views Properly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring 3 MVC Controller Not Returning Views Properly" Watch "Spring 3 MVC Controller Not Returning Views Properly" New topic
Author

Spring 3 MVC Controller Not Returning Views Properly

Jay Doss
Greenhorn

Joined: Aug 16, 2012
Posts: 3
I have recently started learning Spring MVC (using Eclipse with Tomcat 7 server) but am not a new Java developer. I have updated a simple 'Hello World' example to suit to my needs but the views that are being displayed when I execute the program are not rendering properly. When I run the program the welcome page is displayed as expected and it includes 2 links - when I click on either of the links, the URL is correct and is as follows:. However both the artGallery.htm and fashionGallery.htm views display the same content as the welcome page instead of rendering their respective content. Seems like a simple enough fix but what am I missing?? My first guess is something in the Controller is not configured correctly but since I am new to Spring, I need some expert insight :-). Please see the code snippets below and I will provide any additional information that is needed. Thanks so much for your help!

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

Since Spring 2.5 the preferred write your controllers is to use annotations. This way you are not coupled as tightly to the Spring framework. I am going to give you the same recommendation I usually do for those just starting.

First of all download STS (It is eclipse with all the Spring bells and whistles attached). This project is maintained by SpringSource and also has tc server already configured and ready to deploy to (tc server is Tomcat 7 with some extras). Using this you can create one their template projects to get a good idea of how things should be done.

Download STS here:
http://www.springsource.org/sts

Then once you have it create a Spring MVC project using the template

File -> New Spring Template Project -> Spring MVC project


[How To Ask Questions][Read before you PM me]
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

Also please UseCodeTags when posting in the future. And welcome to Java Ranch
Jay Doss
Greenhorn

Joined: Aug 16, 2012
Posts: 3
Thanks for the welcome Bill! I will download STS and see if that can get me on my way any easier (although I think this is a pretty straightforward example but it is giving me a headache!). I will be sure to follow up once I find a resolution.

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

Sure the problem with the example you were looking at is it uses the 'old way'. Newer Spring versions have a much cleaner approach to handling many things which is why I encourage those learning to use the newest version of Spring. When looking at tutorials try to find ones that are using at least Spring 3. The template projects available in STS are great way to learn some of the best practices at least for basic project structure and configuration.

Whenever you see a controller extending some other class in the Spring framework move on to a different example

Good Luck!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring 3 MVC Controller Not Returning Views Properly
 
Similar Threads
HTTP Status 404
Simple navigation rule
Spring MVC - Url Handling Problem
best approach for a Spring MVC implemenation
DispatcherServlet vs ContextLoaderListener?