MVC Starter Files



MVC i.e, Model view controller where Model consist of Dispatcher servlet and spring configuration files. Both are the two starter files every Spring MVC application requires. 

Web.xml—- Dispatcher Servlet.

Servlet.xml—-used for Spring configuration.


Web.xml file-


<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://xmlns.jcp.org/xml/ns/javaee"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

id="WebApp_ID" version="3.1">

<display-name>spring-mvc-demo</display-name>

<absolute-ordering />

<!-- Spring MVC Configs -->

<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->

<servlet>

<servlet-name>dispatcher</servlet-name>

<servlet-org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->

<servlet-mapping>

<servlet-name>dispatcher</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

</web-app>


Spring configuration .xml file name is mentioned in web.xml (in this case spring-mvc-demo) which needs extension of -servlet.xml. So, spring configuration file to be named as 


Spring-mvc-demo-servlet.xml


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<!-- Step 3: Add support for component scanning -->

<context:component-scan base-package="com.eculant.mvc" />

<!-- Step 4: Add support for conversion, formatting and validation support -->

<mvc:annotation-driven/>

<!-- Step 5: Define Spring MVC view resolver -->

<bean

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/view/" />

<property name="suffix" value=".jsp" />

</bean>

</beans>


Further steps:


Go to: Entity Class 

 Controller Classes

jsp files.

Comments

Popular posts from this blog

Depression-A life taking mind disorder

Benefits of Giloy or Tinospora