I learned Spring yesterday and knew that there are two important contents in it, IoC and AOP. But more importantly, Spring is an MVC framework. How does it apply to the Web?
So I looked at Spring MVC again today. Follow the online tutorial step by step, make very breakdown. Create a WEB Project under Eclipse, new -> Project… -> Web -> Dynamic Web Project. Remember to tick “Generate Web.xml Deployment Descriptor” in the last step to automatically Generate web.xml.
Add servlet and listener
The directory for the newly generated Web project looks like this:
The WebContent directory is the website content. Add a test in HTML, Run the as to the tomcat Server, via http://localhost:8080/test/test.html. Access to this page.
But add related servlets, and things change. The servlet I added, following the steps in the tutorial, directs the *.html request address into the JSP. The principle of the inside is not taken into account at the moment, and will be studied later.
Run the Web in Eclipse, of course, Run as Server. This machine is required to install a Web server, I installed Tomcat 7.0.
The result is a 404 error, and nothing is accessed.
Toss over for a long time, I do not know what. Then watch the console output, tomcat tip can’t find the “org. Springframework. Web. Servlet. DispatcherServlet”, I am I clearly cited various jars of spring MVC.
After a while, the packages were probably not published to tomcat, the “Web INF/lib” folder, at runtime. What to do, like this:
Click on the Web project, right-click on properties, Deployment Assemply
Add all the JARS we introduced during development.
Running, normal ah!
One lesson learned is that tomcat’s console output is important, and if it’s not, you should look inside it.
Refer to the tutorial SpringMVC Basics tutorial for a simple getting started example