mvc-overview.notes
Spring Web MVC Overview

An HTTP client, typically a browser, makes a request to the web server.
A controller, which is an annotated POJO class, receives the request, performs some business logic, and adds data to the model.
The model is simply an extension of a
java.util.map and is used to store the data that is to be displayed to the user.
The controller also determines which view is to be displayed.
The view can be one of several technologies but is typically a JSP page which accesses the model using JSTL and JSP expression language.
The view is rendered and the results are sent back to the client.
using-lishys-notes.notes
Guide
The guide pane on the right contains information organized into sections.
Use the

and

buttons to move through the sections, or click an accordion tab (shown below) to go directly to a particular topic.

Code Reference
Each paragraph in the guide is usually associated with a particular piece of code. An orange arrow indicates that the code displayed in the middle pane is relevant to the guide text.

If the arrow is gray, simply click anywhere on the paragraph and the relevant code will be displayed.

Code Highlighter
The highlight feature identifies areas of the code which relate to a word or term in the guide. Hover the mouse over any underlined word and the relevant code will be highlighted.
You can disable the highlighting feature at any time by clicking on the

button.
Don't forget to make the appropriate code page visible by clicking on any paragraph with a gray arrow.
SimpleController.java
package lishy.start.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class SimpleController {
@RequestMapping("/simple-request.html")
public ModelAndView arbitraryMethod() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("show-message");
modelAndView.addObject("message", "This is added to the model with the name 'message'");
return modelAndView;
}
}
show-message.jsp
<html>
<body>
<h1>Simple View</h1>
<p style="color:green">${message}</p>
<p>
<a href="../index.html">back</a>
</p>
</body>
</html>
start-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
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-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="lishy.start.web"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp"/>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="2.5">
<display-name>Getting Started</display-name>
<servlet>
<servlet-name>start</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>start</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
index.html
<html>
<body>
<h1>Getting Started</h1>
<p>
<a href="app/simple-request.html">Simple Request</a>
</p>
</body>
</html>