| First Spring-MVC Project Create Dynamic Web project, provide following information's as stated below - Project name : DemoSpringMVCProject
- Target runtime : set as Apache Tomcat v7.0 server
Click on finish, successfully we have created dynamic web project. Now we have to setup Spring-MVC framework :
- Create **web.xml** under **' WebContent\WEB-INF\ '** folder
- Where DispatcherServlet class Intercepts incoming request and determines which controller handles the request.
- We are going to use servlet-name ' demo ' while creating servlet.xml
- Create **demo-servlet.xml** under **' WebContent\WEB-INF\ '** folder
context:component-scan is used scan all controllers defined under **'com'** package.
ViewResolver Interface
Use to manage mapping between logical and actual views. Predefined implementation of view resolver are available to map the views. Ex: InternalResourceViewResolver, VelocityViewResolver.
To search all jsp pages we have defined **prefix** which is nothing but setter property , it's value is set as **'/WEB-INF/jsp/'**( folder path ) . **Suffix** which is nothing but getter property , it's value is set as **'.jsp'** ( search file with an extension .jsp )
- Add Required Libraries:
Let us add Spring Framework and common logging API libraries in our project. To do this, right click on your project name DemoSpringMVCProject and then follow the following option available in context menu: Build Path -> Configure Build Path to display the Java Build Path window as follows: Now use Add External JARs button available under Libraries tab to add the following core JARs from Spring Framework and Common Logging installation directories:
commons-logging-1.1.1
spring-aop-4.1.6.RELEASE
spring-aspects-4.1.6.RELEASE
spring-beans-4.1.6.RELEASE
spring-context-4.1.6.RELEASE
spring-context-support-4.1.6.RELEASE
spring-core-4.1.6.RELEASE
spring-expression-4.1.6.RELEASE
spring-instrument-4.1.6.RELEASE
spring-instrument-tomcat-4.1.6.RELEASE
spring-jdbc-4.1.6.RELEASE
spring-jms-4.1.6.RELEASE
spring-messaging-4.1.6.RELEASE
spring-orm-4.1.6.RELEASE
spring-oxm-4.1.6.RELEASE
spring-test-4.1.6.RELEASE
spring-tx-4.1.6.RELEASE
spring-web-4.1.6.RELEASE
spring-webmvc-4.1.6.RELEASE
spring-webmvc-portlet-4.1.6.RELEASE
spring-websocket-4.1.6.RELEASE
Let's move towards controller and jsp pages : - Create a com.demo.controller package under src folder.
- Create a LoginController class under com.demo.controller package
- Create a login.jsp and welcome.jsp page under ' WebContent\WEB-INF\jsp\ '
login.jsp welcome.jsp Add DemoSpringMVCProject in localTomcat server and run it on server. This section provides an overview of what spring-mvc is, and why a developer might want to use it. It should also mention any large subjects within spring-mvc, and link out to the related topics. Since the Documentation for spring-mvc is new, you may need to create initial versions of those related topics. |