Spring 3 MVC Controller Not Returning Views Properly
Joined: Aug 16, 2012
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!
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.
Also please UseCodeTags when posting in the future. And welcome to Java Ranch
Joined: Aug 16, 2012
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.
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