SPRING_MVC_BASIC EXAMPL_Govind
Steps to create simple spring MVC example Jars Required
1 First in [Link]
Add the Following entries into the [Link] file As
<servlet> <servlet-name>dispatcher</servlet-name> <servletclass>[Link]</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping>
[Link]
SPRING_MVC_BASIC EXAMPL_Govind
Create one XML file name it as [Link] N add view Resolver N other Beans as <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="[Link] xmlns:xsi="[Link] xsi:schemaLocation="[Link] [Link]
<bean id="viewResolver" class="[Link]"/> <bean id="UrlMapping" class="[Link]"> <property name="urlMap"> <map> <entry key="/[Link]"><ref bean="controller"></ref></entry> </map> </property></bean> <bean id="controller" class="[Link]"></bean> </beans>
[Link] Class:::
Create one class to control eg UserController implement the controller interface package com; import [Link]; import [Link]; import [Link]; import [Link]; public class UserController implements Controller { public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception { [Link]("i m in controller"); String Mess="Hello World"; ModelAndView mav=new ModelAndView("/WEB-INF/[Link]"); [Link]("message",Mess); return mav; }}
SPRING_MVC_BASIC EXAMPL_Govind
4Jsp Files.
Create two Jsp Files [Link] ___ <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[Link] <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <a href="[Link]">Click Here to Test Spring Application...</a> </body> </html>
[Link] <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[Link] <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> Hii this is my second App using SPRING MVC Pattern..... </body> </html>