0% found this document useful (0 votes)
49 views

Springmvc Basic

The document outlines the steps to create a simple Spring MVC application including: 1) Configuring the DispatcherServlet in web.xml, 2) Defining the DispatcherServlet configuration file with view and controller mappings, 3) Implementing a sample controller class, 4) Creating JSP files for the initial page and controller response.

Uploaded by

govindbirajdar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Springmvc Basic

The document outlines the steps to create a simple Spring MVC application including: 1) Configuring the DispatcherServlet in web.xml, 2) Defining the DispatcherServlet configuration file with view and controller mappings, 3) Implementing a sample controller class, 4) Creating JSP files for the initial page and controller response.

Uploaded by

govindbirajdar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SPRING_MVC_BASIC EXAMPL_Govind

Steps to create simple spring MVC example Jars Required

1 First in WEB.XML
Add the Following entries into the web.xml file As
<servlet> <servlet-name>dispatcher</servlet-name> <servletclass>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping>

2Dispatcher-servlet.xml

SPRING_MVC_BASIC EXAMPL_Govind

Create one XML file name it as Dispatcher-servlet.xml N add view Resolver N other Beans as <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"/> <bean id="UrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/abc.html"><ref bean="controller"></ref></entry> </map> </property></bean> <bean id="controller" class="com.UserController"></bean> </beans>

3.UserController Class:::
Create one class to control eg UserController implement the controller interface package com; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; public class UserController implements Controller { public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception { System.out.println("i m in controller"); String Mess="Hello World"; ModelAndView mav=new ModelAndView("/WEB-INF/Nhello.jsp"); mav.addObject("message",Mess); return mav; }}

SPRING_MVC_BASIC EXAMPL_Govind

4Jsp Files.
Create two Jsp Files Index.jsp ___ <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <a href="abc.html">Click Here to Test Spring Application...</a> </body> </html>

Nhello.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <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>

You might also like