Spring Web ,使用annotation和form标签库开发web应用(一)基础配置
来源:互联网 发布:手机制作抽奖软件 编辑:程序博客网 时间:2024/05/29 18:34
摘要:介绍如何配置Spring web用标注实现controller,并且介绍View部分如何用form标签如何与controller相呼应,并有完整的例子,要求读者掌握spring web(过去称为spring mvc)的一般用法, 并了解java web(servlet,jsp)应用的配置和规范。
为什么使用java annotation?
众所周知spring配置xml在一个应用变得原来越大的时候,配置成为一种负担,效率瓶颈可以解决,就是通过使用annotation来识别controller,不需要在配置文件里面来声明controller bean,也不需要声明controller mapping,只要在something-servlet.xml配置文件里面加上一句:
<context:component-scan base-package="com.somecompany.appname.controller" />
在something-servlet.xml被加载的时候会加载这个包里的所有controller。是不是减少了很多工作量?
准备:
springframwork的各个jar之间的关系很微妙,有些jar未必用得到,这里将常用的包都加到classpath中了
org.springframework.core
org.springframework.web
配置WEB-INF/web.xml添加spring-web支持(listener,servlet,filter):
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>icshtml</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>icshtml</servlet-name>
<url-pattern>/ics/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>httpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>httpMethodFilter</filter-name>
<servlet-name>icshtml</servlet-name>
</filter-mapping>
配置WEB-INF/icshtml-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:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- icshtml-servlet.xml被加载的时候会加载这个包里的所有controller -->
<context:component-scan base-package="com.hundsun.ics.controller" />
<!-- 两个view resolver,后一个用来映射返回给客户端页面的jsp文件名,前一个是用来配置controllerbean,这里用不着,因为我们已经改用annotation来声明controller,为了保持兼容,保留原来的配置-->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="1" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/views/" p:suffix=".jsp" p:order="2" />
- Spring Web ,使用annotation和form标签库开发web应用(一)基础配置
- Spring Web ,使用annotation和form标签库开发web应用(一)基础配置
- Spring Web ,使用annotation和form标签库开发web应用(二)请求的映射
- Spring Web ,使用annotation和form标签库开发web应用(二)请求的映射
- 使用Spring进行Web应用开发(一)
- web Form基础一
- 基于Spring MVC的Web应用开发(12) - Form
- 使用Spring 2.5 和 Hibernate 3.2 开发MVC Web程序(基于annotation特性)
- Java WEB开发中对jstl的应用一(标签库引用)
- 基于 OSGi 和 Spring 开发 Web 应用
- 基于 OSGi 和 Spring 开发 Web 应用
- 基于 OSGi 和 Spring 开发 Web 应用
- 基于 OSGi 和 Spring 开发 Web 应用
- 基于 OSGi 和 Spring 开发 Web 应用
- 基于 OSGi 和 Spring 开发 Web 应用
- 基于 OSGi 和 Spring 开发 Web 应用
- 基于 OSGi 和 Spring 开发 Web 应用
- 基于 OSGi 和 Spring 开发 Web 应用
- 自助Linux之问题诊断工具strace
- 关于Eclipse开发android和java编译器出现卡死的假象
- 1.4.5 收集trace日志
- codeblocks 使用指南z
- 猴子爬山问题
- Spring Web ,使用annotation和form标签库开发web应用(一)基础配置
- 理解 chroot
- 最长公共子序列问题
- Spring Web ,使用annotation和form标签库开发web应用(二)请求的映射
- 安卓onInterceptTouchEvent和onTouchEvent详解
- androidL,自定义状态栏
- Spring MVC和Struts2的比较
- Xcode6中添加pch文件
- 关于色彩的常识