- 浏览: 76943 次
文章分类
- 全部博客 (89)
- web service (9)
- subversion (1)
- JBOSS (3)
- interview (23)
- jQery (2)
- ExtJs (0)
- Axis (0)
- Design pattern (3)
- Agile (2)
- mutithread (0)
- Core Java (24)
- programming methods (1)
- SSH (7)
- jee design (1)
- OO (4)
- books (8)
- other (1)
- JSF (7)
- seam (2)
- Weblogic (4)
- JPA (1)
- ADF (1)
- Spring (5)
- Tomcat (1)
- DWR (2)
- JEE (3)
- Servlet (1)
- EJB (1)
- JDBC (3)
最新评论
-
iloveflower:
呵呵。好好学习。。。。。。。。。。。。
java 读书 -
Eric.Yan:
看了一点,不过是电子版的……你这一说到提醒我了,还要继续学习哈 ...
java 读书
http://sites.google.com/site/sritechforjava/spring-docs/spring-mvc-basics
Assuming that the student knows basic web application structure and all the configuration files required for Basic web application.
Assuming that the student knows Servlets.
To create Annotation based Spring MVC web application please follow the below steps:
Step 1 : Update your web.xml file with following configuration:
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
DispatcherServlet - Spring's Web MVC framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for upload files.
A central servlet that dispatches requests to controllers and offers other functionality facilitating the development of web applications.
Is an expression of the “Front Controller” design pattern.
It is completely integrated with the Spring IoC container and as such allows you to use every other feature that Spring has.
The framework will, on initialization of a DispatcherServlet, look for a file named [servlet-name]-servlet.xml in the WEB-INF directory of your web application and create the beans defined there.
Step 2 : Create spring-mvc-servlet.xml under WEB-INF directory. (Observe that the file name should start with servlet-name of the DispatcherServlet-servlet.xml.)
Step 3 : The Basic spring-mvc-servlet.xml looks like below:
<?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"
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">
</beans>
Step 4 : spring-mvc-servlet.xml file will contain all of your Spring Web MVC-specific components (beans). The exact location of this configuration file can be changed via a DispatcherServlet initialization parameter. You can specify that in web.xml like below:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/spring/spring-context.xml</param-value>
</context-param>
Step 5 : Just as with any other view technology you're integrating with Spring, for JSPs you'll need a view resolver that will resolve your views. The most commonly used view resolvers when developing with JSPs are the InternalResourceViewResolver and the ResourceBundleViewResolver.
Add the below configuration in your spring-mvc-servlet.xml file: (I am using InternalResourceViewResolver here in this example)
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
Step 6 : Here as we are going to use annotations instead of configuring our Controllers in xml files, we also need to add the following configuration in spring-mvc-servlet.xml file, so that container scans all the controller components at the initialization of DispatcherServlet and they will be available.
<context:component-scan base-package="com.sritech.samples">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
Step 7 : Your web application lib directory also need the following spring jars:
spring.jar
spring-webmvc.jar
commons-logging.jar
These jars will be deployed to the server and they are also used during the build process.
The above configuration allows your DispatcherServlet to scan for all the controllers in the specified package (Ex: com.sritech.samples).
All above 6 Steps are one time configuration you have to do to create your annotation based Spring MVC application.
Example 1:- Create Welcome Page using SimpleWelcomeController and Simple JSP.
Step 1 : Create the controller class:
package com.sritech.samples.mvc.example1;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class SimpleWelcomeController {
@RequestMapping("/example1/welcome.htm")
public void elementaryGreeter() {
}
}
The @Controller annotation indicates that a particular class serves the role of a controller. There is no need to extend any controller base class or reference the Servlet API. You are of course still able to reference Servlet-specific features if you need to. The basic purpose of the @Controller annotation is to act as a stereotype for the annotated class, indicating its role. The dispatcher will scan such annotated classes for mapped methods, detecting @RequestMapping annotations.
The @RequestMapping annotation is used to map URLs like '/example1/welcome.htm' onto an entire class or a particular handler method.
Step 2 : Create the JSP.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Welcome to Spring MVC</title>
</head>
<body>
Hello everyone! Welcome to Spring MVC: Example 1
</body>
</html>
Step 3 : Now create the war file and deploy into your Tomcat Server. (Any Web Server or application Server).
Step 4 : After the application is deployed go the below link:
http://server-name:portNumber/spring-mvc-samples/example1/welcome.htm
Step 5 : You will be seeing the following output on your screen:
Welcome to Spring MVCHello everyone! Welcome to Spring MVC: Example 1
Surprised!
Continue...
Assuming that the student knows basic web application structure and all the configuration files required for Basic web application.
Assuming that the student knows Servlets.
To create Annotation based Spring MVC web application please follow the below steps:
Step 1 : Update your web.xml file with following configuration:
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
DispatcherServlet - Spring's Web MVC framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for upload files.
A central servlet that dispatches requests to controllers and offers other functionality facilitating the development of web applications.
Is an expression of the “Front Controller” design pattern.
It is completely integrated with the Spring IoC container and as such allows you to use every other feature that Spring has.
The framework will, on initialization of a DispatcherServlet, look for a file named [servlet-name]-servlet.xml in the WEB-INF directory of your web application and create the beans defined there.
Step 2 : Create spring-mvc-servlet.xml under WEB-INF directory. (Observe that the file name should start with servlet-name of the DispatcherServlet-servlet.xml.)
Step 3 : The Basic spring-mvc-servlet.xml looks like below:
<?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"
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">
</beans>
Step 4 : spring-mvc-servlet.xml file will contain all of your Spring Web MVC-specific components (beans). The exact location of this configuration file can be changed via a DispatcherServlet initialization parameter. You can specify that in web.xml like below:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/spring/spring-context.xml</param-value>
</context-param>
Step 5 : Just as with any other view technology you're integrating with Spring, for JSPs you'll need a view resolver that will resolve your views. The most commonly used view resolvers when developing with JSPs are the InternalResourceViewResolver and the ResourceBundleViewResolver.
Add the below configuration in your spring-mvc-servlet.xml file: (I am using InternalResourceViewResolver here in this example)
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
Step 6 : Here as we are going to use annotations instead of configuring our Controllers in xml files, we also need to add the following configuration in spring-mvc-servlet.xml file, so that container scans all the controller components at the initialization of DispatcherServlet and they will be available.
<context:component-scan base-package="com.sritech.samples">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
Step 7 : Your web application lib directory also need the following spring jars:
spring.jar
spring-webmvc.jar
commons-logging.jar
These jars will be deployed to the server and they are also used during the build process.
The above configuration allows your DispatcherServlet to scan for all the controllers in the specified package (Ex: com.sritech.samples).
All above 6 Steps are one time configuration you have to do to create your annotation based Spring MVC application.
Example 1:- Create Welcome Page using SimpleWelcomeController and Simple JSP.
Step 1 : Create the controller class:
package com.sritech.samples.mvc.example1;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class SimpleWelcomeController {
@RequestMapping("/example1/welcome.htm")
public void elementaryGreeter() {
}
}
The @Controller annotation indicates that a particular class serves the role of a controller. There is no need to extend any controller base class or reference the Servlet API. You are of course still able to reference Servlet-specific features if you need to. The basic purpose of the @Controller annotation is to act as a stereotype for the annotated class, indicating its role. The dispatcher will scan such annotated classes for mapped methods, detecting @RequestMapping annotations.
The @RequestMapping annotation is used to map URLs like '/example1/welcome.htm' onto an entire class or a particular handler method.
Step 2 : Create the JSP.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Welcome to Spring MVC</title>
</head>
<body>
Hello everyone! Welcome to Spring MVC: Example 1
</body>
</html>
Step 3 : Now create the war file and deploy into your Tomcat Server. (Any Web Server or application Server).
Step 4 : After the application is deployed go the below link:
http://server-name:portNumber/spring-mvc-samples/example1/welcome.htm
Step 5 : You will be seeing the following output on your screen:
Welcome to Spring MVCHello everyone! Welcome to Spring MVC: Example 1
Surprised!
Continue...
发表评论
-
SpringMVC, JQuery, JSON
2012-06-07 21:33 1418http://viralpatel.net/blogs/201 ... -
step by step guide to DWR 3.RC1 and Sprig 3.0.2 Integration
2012-05-25 04:16 1473step by step guide to DWR 3.RC1 ... -
dwr step by step
2012-05-25 03:50 772http://blog.csdn.net/bruesz/art ... -
DWR+SpringMVC integration
2012-05-17 22:04 1148http://directwebremoting.org/dw ... -
Spring MVC Tutorial
2012-05-16 03:57 2324http://www.mkyong.com/tutorials ... -
关键字:Hibernate注释大全收藏
2012-05-16 03:50 621关键字:Hibernate注释大全收藏 声明实体Bean ... -
struts1.x、hibernate和spring2.x集成方式
2012-05-15 23:17 643come from: http://blog.csdn.net ... -
Spring3.x 之ScrollableSupportJdbcTemplate
2012-05-15 01:29 994public class ScrollableSupportJ ... -
Spring的JTA管理
2012-03-18 21:29 663http://www.iteye.com/topic/1114 ... -
Struts+Spring+Hibernate(JPA) + Ajax整合详解
2012-03-15 23:30 764Struts+Spring+Hibernate(JPA) + ...
相关推荐
个人认为相当适合入门和知识巩固!! 一、前言 二、spring mvc 核心类与接口 ...十九、 <mvc:annotation-driven /> 到底做了什么工作 二十、 本文中springMVC.xml配置文件是核心,这里给一个下载地址
Spring MVC 教程 快速入门 深入分析 目录 一、前言 二、spring mvc 核心类与接口 三、spring mvc 核心流程图 四、spring mvc DispatcherServlet说明 ...十九、 <mvc:annotation-driven /> 到底做了什么工作
一、前言 二、spring mvc 核心类与接口 三、spring mvc 核心流程图 四、spring mvc ...十九、 <mvc:annotation-driven /> 到底做了什么工作 二十、 本文中springMVC.xml配置文件是核心,这里给一个下载地址
Table of Contents Introduction Chapter 1: The Spring Framework Chapter 2: Model 2 and the MVC Pattern Chapter 3: Introduction to Spring MVC Chapter 4: Annotation-Based Controllers Chapter 5: Data ...
SpingMVC 使用Annotation使用Spring MVC的演示应用程序
With the power of annotation-based configuration, Spring MVC makes web application development easy for developers. This book is a great companion for beginners who want to learn Spring MVC. With ...
Spring MVC internationalization annotation example 这个是annotation 方式的国际化 访问http://localhost:8080/login.htm
Spring MVC 整合Hibernate的一个小小的用例,适合初学Spring MVC 的学者。
一个简单的spring mvc登录案例,采用的是annotation方式。
博文链接:https://pesome.iteye.com/blog/236273
spring mvc annotation interceptor
Spring annotation 样例
Spring mvc注解方式实现Controller
Spring mvc Aop+annotation实现系统日志记录功能实现的jar包asm-3.3.jar ,aspectjrt.jar , aspectjweaver.jar , cglib-nodep-2.1_3.jar , spring-aop.jar
这里提供了Spring3 MVC中较为常见的使用方法,主要是利用Spring3官方文档建议使用的Annotation进行开发的一般步骤,包含了常见的集中Annotation的使用方法。
spring annotation注解 使用Spring注解来注入属性
利用Spring mvc annotation写成的demo
Annotation-Based Validation with the Spring Bean Validation Framework
SpringMVC: 一、前言 二、spring mvc 核心类与接口 三、spring mvc 核心流程图 ...十九、 <mvc:annotation-driven /> 到底做了什么工作 二十、 本文中springMVC.xml配置文件是核心,这里给一个下载地址