Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring 3 MVC Controller Not Returning Views Properly

 
Jay Doss
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also please UseCodeTags when posting in the future. And welcome to Java Ranch
 
Jay Doss
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic