1、结构

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaXRscWk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

2、控制器

  1. package com.ai.customer.controller;
  2.  
  3. import java.io.IOException;
  4.  
  5. import javax.servlet.ServletContext;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9.  
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.ui.ModelMap;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.RequestParam;
  16. import org.springframework.web.context.request.RequestContextHolder;
  17. import org.springframework.web.context.request.ServletRequestAttributes;
  18. import org.springframework.web.context.request.ServletWebRequest;
  19. import org.springframework.web.servlet.ModelAndView;
  20. import org.springframework.web.servlet.support.RequestContext;
  21.  
  22. import com.ai.customer.model.CustomerInfo;
  23. import com.ai.customer.service.ICustomerService;
  24.  
  25. /*
  26. * @Controller
  27. * 控制器
  28. *
  29. * @Service
  30. * 用于标注业务层组件
  31. *
  32. * @Repository
  33. * 用于标注数据訪问组件。即DAO组件
  34. *
  35. * @Component
  36. * 泛指组件,当组件不好归类的时候我们能够使用这个注解进行标注,(如今能够都用此注解)
  37. * 同上事实上跟@Service/@Repository/@Controller 一样仅仅只是它们 利用分层 好区分
  38. *
  39. * @Autowired\@Resource
  40. * 自己主动注入 实现的的是 setXxx()方法 getXxx()方法
  41. *
  42. * @RequestMapping(value='xxx.do',method=RequestMethod.GET/RequestMethod.POST/..)
  43. * value訪问路径/method请发的方法,注:请求方法一旦设定仅仅能使用指定的方法訪问
  44. * 在类前面定义,则将url和类绑定。
  45. * 在方法前面定义,则将url和类的方法绑定
  46. *
  47. * @RequestParam("name") ==uname
  48. * 一般用于将指定的请求參数付给方法中形參
  49. *
  50. * @Scope
  51. * 创建 bean的作用域 singleton-->多例 Property-->多例 还有request 等等
  52. * 使用reqeust 须要在web.xml 配置监听器 详细去网上搜索
  53. *
  54. */
  55.  
  56. @Controller
  57. public class CustomerAction {
  58.  
  59. @Autowired
  60. private ICustomerService customerService;
  61.  
  62. @RequestMapping(value="/login.do")
  63. public String postLogingMethod(HttpServletRequest reqeust){
  64. System.out.println("訪问到了控制器");
  65. System.out.println(customerService);
  66. CustomerInfo cus=customerService.queryCustomer().get(0);
  67. System.out.println("身份证Id"+cus.getCardid());
  68. reqeust.getSession().setAttribute("cus", cus);
  69. return "page/admin/index";
  70. }
  71.  
  72. /*
  73. * @RequestParam 使用
  74. * @RequestParam("name") ==uname 一般用于将指定的请求參数付给方法中形參
  75. */
  76. @RequestMapping("/param.do" )
  77. public String paramMethod(@RequestParam("name")String uname){
  78. System.out.println("uname:"+uname);
  79. //重定向 页面
  80. return "redirect:index.jsp";
  81. }
  82.  
  83. /*
  84. * 页面传递过来的參数 自己主动赋值 xxx.do?
  85.  
  86. name=张三&customerid=12342423 post get请求皆可
  87. * ajax $.xxx("xxx.do",{name:'张三',customerid:'123435345'},function(data){});
  88. */
  89. @RequestMapping("/rq.do")
  90. public String allMethod(String customerid,String name){
  91. System.out.println(customerid+":"+name);
  92. return "index";
  93. }
  94.  
  95. /*
  96. * 封装实体对象 表单提交数据 表单中cus.name名
  97. * <input type="text" name="cus.name">
  98. * <input type="text" name="cus.customerid">
  99. */
  100. @RequestMapping("/cus.do")
  101. public String setCustomer(CustomerInfo cus){
  102. System.out.println(cus.getCustomerid()+":"+cus.getName());
  103. return "index";
  104. }
  105.  
  106. /*springmvc 中获取request对象
  107. * 1、能够直接在方法中定义 getReqeust(CustomerInfo cus,HttpServletRequest req)
  108. *
  109. * 2、使用注解Autowired
  110. * @Autowired
  111. * private HttpServletRequest request;
  112. *
  113. * 3、使用例如以下方法
  114. * ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
  115. * servletRequestAttributes.getRequest();
  116. *
  117. */
  118. @RequestMapping("/reqeust.do")
  119. public String getReqeust(CustomerInfo cus,HttpServletRequest req){
  120. //获取reqeust对象
  121. req.setAttribute("cus", cus);
  122. //获取session对象
  123. req.getSession();
  124. return "index";
  125. }
  126.  
  127. /* 获取reponse 能够使用例如以下方法 也能够使用:在方法中传递
  128. * getResponse(String name,String customerid,HttpservletResponse response)
  129. */
  130. @RequestMapping("/response.do")
  131. public void getResponse(String name,String customerid,HttpServletResponse response){
  132.  
  133. response.setContentType("text/html;charset=utf-8");
  134.  
  135. System.out.println(name+":"+customerid);
  136. try {
  137. response.getWriter().write(customerid.toString());
  138. } catch (IOException e) {
  139. e.printStackTrace();
  140. }
  141. }
  142.  
  143. /*ModelAndView 与 ModelMap 的差别
  144. *
  145. * ModelAndView
  146. * 作用一 :设置转向地址/对象必须手动创建(主要差别)
  147. *
  148. * 作用二:用于传递控制方法处理结果数据到结果页面,
  149. * 也就是说我们把须要在结果页面上须要的数
  150. * 据放到ModelAndView对象中就可以,他
  151. * 的作用相似于request对象的setAttr
  152. * ibute方法的作用,用来在一个请求过程中
  153. * 传递处理的数据。通过下面方法向页面传递 參数:addObject(String key,Object value);
  154. *
  155. *
  156. * ModelMap
  157. *一、 ModelMap的实例是由bboss mvc框架自己主动创建并作为控制器方法參数传入。
  158. * 用户无需自己创建。
  159. *
  160. * 二、ModelMap对象主要用于传递控制方法处理数据到结果页面,也就是说我们把结果页面上须要的数据放到ModelMap对象中就可以,
  161. * 他的作用相似于request对象的setAttribute方法的作用。用来在一个请求过程中传递处理的数据。
  162.  
  163. 通过下面方法向页面传递參数:
  164. * addAttribute(String key,Object value);
  165. * 在页面上能够通过el变量方式$key或者bboss的一系列数据展示标签获取并展示modelmap中的数据。
  166. * modelmap本身不能设置页面跳转的url地址别名或者物理跳转地址,那么我们能够通过控制器方法的返回值来设置跳转url地址
  167. * 别名或者物理跳转地址。
  168.  
  169. */
  170.  
  171. @RequestMapping("/modelmap.do")
  172. public String modelMapMethod(String name,ModelMap model) {
  173. //将数据放置到ModelMap对象model中,第二个參数能够是不论什么java类型
  174. model.addAttribute("modelMap",name);
  175. //返回跳转地址
  176. return "index";
  177. }
  178.  
  179. @RequestMapping("/modelandmap.do")
  180. public ModelAndView modelAndMapMethod(String name) {
  181. //构建ModelAndView实例,并设置跳转地址
  182. ModelAndView view = new ModelAndView("index");
  183. //将数据放置到ModelAndView对象view中,第二个參数能够是不论什么java类型
  184. view.addObject("modelAndMap",name);
  185. //返回ModelAndView对象view
  186. return view;
  187. }
  188.  
  189. }

3、DAO接口

  1. package com.ai.customer.dao;
  2.  
  3. import java.util.List;
  4.  
  5. import com.ai.customer.model.CustomerInfo;
  6.  
  7. public interface ICustomerDao {
  8.  
  9. //查询Customer
  10. public List<CustomerInfo> queryCustomer();
  11. public String all();
  12. }

4、DAO接口实现

  1. package com.ai.customer.daoimpl;
  2.  
  3. import java.util.List;
  4.  
  5. import org.hibernate.Hibernate;
  6. import org.hibernate.Session;
  7. import org.hibernate.SessionFactory;
  8. import org.hibernate.cfg.Configuration;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Component;
  11. import org.springframework.stereotype.Repository;
  12.  
  13. import com.ai.customer.dao.ICustomerDao;
  14. import com.ai.customer.model.CustomerInfo;
  15.  
  16. @Repository
  17. public class CustomerDao implements ICustomerDao {
  18.  
  19. @Autowired
  20. private SessionFactory sessionFactory;
  21.  
  22. // public void setSessionFactory(SessionFactory sessionFactory) {
  23. // this.sessionFactory = sessionFactory;
  24. // }
  25.  
  26. public List<CustomerInfo> queryCustomer() {
  27.  
  28. //System.out.println(sessionFactory);
  29.  
  30. //Configuration config=new Configuration().configure("config/hibernet/hibernate.cfg.xml");
  31.  
  32. //SessionFactory f=config.buildSessionFactory();
  33.  
  34. Session session=sessionFactory.openSession();
  35.  
  36. List<CustomerInfo> cus=session.createQuery("from CustomerInfo").list();
  37.  
  38. session.close();
  39.  
  40. return cus;
  41. }
  42.  
  43. public String all(){
  44.  
  45. return "注解成功";
  46. }
  47.  
  48. public static void main(String[] args) {
  49.  
  50. Configuration config=new Configuration().configure("config/hibernet/hibernate.cfg.xml");
  51.  
  52. SessionFactory f=config.buildSessionFactory();
  53.  
  54. Session session=f.openSession();
  55.  
  56. List<CustomerInfo> cus=session.createQuery("from CustomerInfo").list();
  57.  
  58. session.close();
  59.  
  60. System.out.println(cus.get(0).getCustomerid());
  61.  
  62. // System.out.println(f.getCurrentSession().createQuery("from CustomerInfo").list());
  63. }
  64. }

5、实体类

  1. package com.ai.customer.model;
  2.  
  3. import java.io.Serializable;
  4.  
  5. public class CustomerInfo implements Serializable {
  6.  
  7. /**
  8. *
  9. */
  10. private static final long serialVersionUID = 1L;
  11.  
  12. private String customerid;//个人编号
  13.  
  14. private String cardid;//身份证id
  15.  
  16. private String name;//姓名
  17.  
  18. private String sex;//性别(男、女)
  19.  
  20. private String birthDate;//出生日期
  21.  
  22. private String householdRegister;//户籍所在地址
  23.  
  24. private String photo;//照片
  25.  
  26. private String regTime;
  27.  
  28. private String loginCount;
  29.  
  30. private String lastLoginTime;
  31.  
  32. public String getCustomerid() {
  33. return customerid;
  34. }
  35.  
  36. public void setCustomerid(String customerid) {
  37. this.customerid = customerid;
  38. }
  39.  
  40. public String getCardid() {
  41. return cardid;
  42. }
  43.  
  44. public void setCardid(String cardid) {
  45. this.cardid = cardid;
  46. }
  47.  
  48. public String getName() {
  49. return name;
  50. }
  51.  
  52. public void setName(String name) {
  53. this.name = name;
  54. }
  55.  
  56. public String getSex() {
  57. return sex;
  58. }
  59.  
  60. public void setSex(String sex) {
  61. this.sex = sex;
  62. }
  63.  
  64. public String getBirthDate() {
  65. return birthDate;
  66. }
  67.  
  68. public void setBirthDate(String birthDate) {
  69. this.birthDate = birthDate;
  70. }
  71.  
  72. public String getHouseholdRegister() {
  73. return householdRegister;
  74. }
  75.  
  76. public void setHouseholdRegister(String householdRegister) {
  77. this.householdRegister = householdRegister;
  78. }
  79.  
  80. public String getPhoto() {
  81. return photo;
  82. }
  83.  
  84. public void setPhoto(String photo) {
  85. this.photo = photo;
  86. }
  87.  
  88. public String getRegTime() {
  89. return regTime;
  90. }
  91.  
  92. public void setRegTime(String regTime) {
  93. this.regTime = regTime;
  94. }
  95.  
  96. public String getLoginCount() {
  97. return loginCount;
  98. }
  99.  
  100. public void setLoginCount(String loginCount) {
  101. this.loginCount = loginCount;
  102. }
  103.  
  104. public String getLastLoginTime() {
  105. return lastLoginTime;
  106. }
  107.  
  108. public void setLastLoginTime(String lastLoginTime) {
  109. this.lastLoginTime = lastLoginTime;
  110. }
  111.  
  112. public static long getSerialversionuid() {
  113. return serialVersionUID;
  114. }
  115. }

6、customer.hbm.xml配置文件

  1. <!DOCTYPE hibernate-mapping PUBLIC
  2. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  3. "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  4.  
  5. <hibernate-mapping>
  6.  
  7. <class name="com.ai.customer.model.CustomerInfo" table="customerInfo">
  8.  
  9. <id name="customerid" column="customerid" type="java.lang.String">
  10. <generator class="assigned"/>
  11. </id>
  12.  
  13. <property name="cardid" type="java.lang.String"/>
  14. <property name="name" type="java.lang.String"/>
  15. <property name="sex" type="java.lang.String"/>
  16. <property name="birthDate" type="java.lang.String"/>
  17. <property name="householdRegister" type="java.lang.String"/>
  18. <property name="photo" type="java.lang.String"/>
  19. <property name="regTime" type="java.lang.String"/>
  20. <property name="loginCount" type="java.lang.String"/>
  21. <property name="lastLoginTime" type="java.lang.String"/>
  22. </class>
  23.  
  24. </hibernate-mapping>

7、service 接口

  1. package com.ai.customer.service;
  2.  
  3. import java.util.List;
  4.  
  5. import com.ai.customer.model.CustomerInfo;
  6.  
  7. public interface ICustomerService {
  8.  
  9. //查询Customer
  10. public List<CustomerInfo> queryCustomer();
  11.  
  12. public String all();
  13. }

8、service接口实现

  1. package com.ai.customer.serviceImpl;
  2.  
  3. import java.util.List;
  4.  
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Component;
  7. import org.springframework.stereotype.Repository;
  8. import org.springframework.stereotype.Service;
  9.  
  10. import com.ai.customer.dao.ICustomerDao;
  11. import com.ai.customer.model.CustomerInfo;
  12. import com.ai.customer.service.ICustomerService;
  13.  
  14. @Service
  15. public class CustomerService implements ICustomerService{
  16.  
  17. @Autowired
  18. private ICustomerDao customerDao;
  19.  
  20. public List<CustomerInfo> queryCustomer() {
  21. return customerDao.queryCustomer();
  22. }
  23.  
  24. public String all() {
  25. // TODO Auto-generated method stub
  26. return customerDao.all();
  27. }
  28.  
  29. }

9、hibernate.cfg.xml配置文件

  1. <!DOCTYPE hibernate-configuration PUBLIC
  2. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  3. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  4.  
  5. <hibernate-configuration>
  6. <!--表明下面的配置是针对session-factory配置的。SessionFactory是Hibernate中的一个类,这个类主要负责保存HIbernate的配置信息,以及对Session的操作-->
  7. <session-factory>
  8.  
  9. <!--hibernate.dialect 仅仅是Hibernate使用的数据库方言,就是要用Hibernate连接那种类型的数据库server。
  10.  
  11. -->
  12. <property name="dialect">
  13. org.hibernate.dialect.MySQLDialect
  14. </property>
  15. <property name="connection.url">
  16. jdbc:mysql://localhost:3306/data
  17. </property>
  18. <property name="connection.username">root</property>
  19. <property name="connection.password">123456</property>
  20. <property name="connection.driver_class">
  21. com.mysql.jdbc.Driver
  22. </property>
  23.  
  24. <!--数据库连接池的大小-->
  25. <property name="hibernate.connection.pool.size">10</property>
  26.  
  27. <!--是否在后台显示Hibernate用到的SQL语句,开发时设置为true,便于差错,程序执行时能够在Eclipse的控制台显示Hibernate的执行Sql语句。项目部署后能够设置为false,提高执行效率-->
  28. <property name="hibernate.show_sql">true</property>
  29.  
  30. <!--jdbc.fetch_size是指Hibernate每次从数据库中取出并放到JDBC的Statement中的记录条数。
  31.  
  32. Fetch Size设的越大,读数据库的次数越少,速度越快。Fetch Size越小。读数据库的次数越多。速度越慢-->
  33. <property name="jdbc.fetch_size">50</property>
  34.  
  35. <!--jdbc.batch_size是指Hibernate批量插入,删除和更新时每次操作的记录数。Batch Size越大,批量操作的向数据库发送Sql的次数越少,速度就越快。相同耗用内存就越大-->
  36. <property name="jdbc.batch_size">23</property>
  37.  
  38. <!--jdbc.use_scrollable_resultset是否同意Hibernate用JDBC的可滚动的结果集。对分页的结果集。对分页时的设置很有帮助-->
  39. <property name="jdbc.use_scrollable_resultset">false</property>
  40.  
  41. <!--connection.useUnicode连接数据库时是否使用Unicode编码-->
  42. <property name="Connection.useUnicode">true</property>
  43.  
  44. <!--connection.characterEncoding连接数据库时数据的传输字符集编码方式。最好设置为gbk。用gb2312有的字符不全-->
  45. <property name="connection.characterEncoding">gbk</property>
  46.  
  47. <!--连接池的最小连接数-->
  48. <property name="hibernate.c3p0.min_size">5</property>
  49.  
  50. <!--最大连接数-->
  51. <property name="hibernate.c3p0.max_size">500</property>
  52.  
  53. <!--连接超时时间-->
  54. <property name="hibernate.c3p0.timeout">1800</property>
  55.  
  56. <!--statemnets缓存大小-->
  57. <property name="hibernate.c3p0.max_statements">0</property>
  58.  
  59. <!--每隔多少秒检測连接是否可正常使用 -->
  60. <property name="hibernate.c3p0.idle_test_period">121</property>
  61.  
  62. <!--当池中的连接耗尽的时候,一次性添加的连接数量,默觉得3-->
  63. <property name="hibernate.c3p0.acquire_increment">5</property>
  64.  
  65. <property name="hibernate.c3p0.validate">true</property>
  66.  
  67. <mapping resource="com/ai/customer/model/CustomerInfo.hbm.xml" />
  68.  
  69. </session-factory>
  70.  
  71. </hibernate-configuration>

10、spring-application.xml配置

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://www.springframework.org/schema/context
  9. http://www.springframework.org/schema/context/spring-context-3.2.xsd">
  10.  
  11. <!-- 配置数据源
  12. <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  13.  
  14. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  15.  
  16. <property name="url" value="jdbc:mysql://localhost/data"/>
  17.  
  18. <property name="username" value="root"/>
  19.  
  20. <property name="password" value="123456"/>
  21. </bean>
  22. -->
  23. <!-- hibernet 配置 -->
  24. <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  25.  
  26. <!-- <property name="dataSource" ref="dataSource"/> -->
  27.  
  28. <property name="configLocation">
  29. <value>classpath:config/hibernet/hibernate.cfg.xml</value>
  30. </property>
  31.  
  32. </bean>
  33.  
  34. <!-- 配置事务 -->
  35. <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  36. <property name="sessionFactory" ref="sessionFactory" />
  37. </bean>
  38.  
  39. <!-- 使用代理配置事务管理 -->
  40. <bean id="transactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
  41. <property name="transactionManager" ref="transactionManager" />
  42. <property name="transactionAttributes">
  43. <props>
  44. <!-- 假设当前没有事务,就新建一个事务,假设已经存在一个事务中,增加到这个事务中。 -->
  45. <prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
  46. <prop key="modify*">PROPAGATION_REQUIRED,-myException</prop>
  47. <prop key="del*">PROPAGATION_REQUIRED</prop>
  48. <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
  49. <prop key="*">PROPAGATION_REQUIRED</prop>
  50. </props>
  51. </property>
  52. </bean>
  53. </beans>

11、spring-mvc.xml配置

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://www.springframework.org/schema/context
  9. http://www.springframework.org/schema/context/spring-context-3.2.xsd
  10. http://www.springframework.org/schema/mvc
  11. http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
  12.  
  13. <!-- 扫描包 -->
  14. <context:component-scan base-package="com.ai.customer" />
  15.  
  16. <!-- 启动注解 -->
  17. <mvc:annotation-driven />
  18.  
  19. <!-- 文件上传 -->
  20. <bean id="multipartResolver"
  21. class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  22. <!-- 设置上传文件的最大尺寸为10MB -->
  23. <property name="maxUploadSize">
  24. <value>10000000</value>
  25. </property>
  26. </bean>
  27.  
  28. <!-- 静态文件訪问 -->
  29. <mvc:default-servlet-handler/>
  30. <!-- 对模型视图名称的解析,即在模型视图名称加入前后缀 -->
  31. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
  32.  
  33. <property name="prefix" value="/"/>
  34. <property name="suffix" value=".jsp"/>
  35. </bean>
  36.  
  37. </beans>

12、web.xml配置文件

  1. <?xml version="1.0" encoding="UTF-8"?
  2.  
  3. >
  4. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xmlns="http://java.sun.com/xml/ns/javaee"
  6. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  7. http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  8. <display-name>springmvc_sh</display-name>
  9. <welcome-file-list>
  10. <welcome-file>login/login.jsp</welcome-file>
  11. </welcome-file-list>
  12. <context-param>
  13. <param-name>contextConfigLocation</param-name>
  14. <param-value>classpath*:config/spring/spring-appliction.xml</param-value>
  15. </context-param>
  16. <listener>
  17. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  18. </listener>
  19. <servlet>
  20. <servlet-name>spring</servlet-name>
  21. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  22. <init-param>
  23. <param-name>contextConfigLocation</param-name>
  24. <param-value>classpath*:config/spring/spring-*.xml</param-value>
  25. </init-param>
  26. <load-on-startup>1</load-on-startup>
  27. </servlet>
  28. <servlet-mapping>
  29. <servlet-name>spring</servlet-name>
  30. <url-pattern>*.do</url-pattern>
  31. </servlet-mapping>
  32. <listener>
  33. <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  34. </listener>
  35. <filter>
  36. <filter-name>codeUTF-8</filter-name>
  37. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  38. <init-param>
  39. <param-name>encoding</param-name>
  40. <param-value>UTF-8</param-value>
  41. </init-param>
  42. <init-param>
  43. <param-name>forceEncoding</param-name>
  44. <param-value>true</param-value>
  45. </init-param>
  46. </filter>
  47. <filter-mapping>
  48. <filter-name>codeUTF-8</filter-name>
  49. <url-pattern>/*</url-pattern>
  50. </filter-mapping>
  51.  
  52. <error-page>
  53. <error-code>404</error-code>
  54. <location>/login/loginIput.jsp</location>
  55. </error-page>
  56. <error-page>
  57. <error-code>500</error-code>
  58. <location>/login/login.jsp</location>
  59. </error-page>
  60. </web-app>

springmvc 例的更多相关文章

  1. SpringMVC常用注解實例詳解3:@ResponseBody

    我的開發環境框架:        springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...

  2. SpringMVC常用注解實例詳解2:@ModelAttribute

    我的開發環境框架:        springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...

  3. SpringMVC常用注解實例詳解1:@Controller,@RequestMapping,@RequestParam,@PathVariable

    我的開發環境 框架:        springmvc+spring+freemarker 開發工具: springsource-tool-suite-2.9.0 JDK版本: 1.6.0_29 to ...

  4. SpringMvc 单例

    struts2的controller是多例,是因为其中有modeldriven将比如user 或者其他属性暴露出来,接受属性,特别是继承了actionsupport之后,fielderror的属性也会 ...

  5. Eclipse的maven构建一个web项目,以构建SpringMVC项目为例

    http://www.cnblogs.com/javaTest/archive/2012/04/28/2589574.html springmvc demo实例教程源代码下载:http://zuida ...

  6. 最全SpringMVC具体演示样例实战教程

    一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先.导入SpringMVC须要的jar包. 2.加入Web.xml配置文件里关于SpringMVC的配置 <!--conf ...

  7. SpringMVC+Spring+Hibernate的小样例

    Strusts2+Spring+Hibernate尽管是主流的WEB开发框架,可是SpringMVC有越来越多的人使用了.确实也很好用.用得爽! 这里实现了一个SpringMVC+Spring+Hib ...

  8. SpringMVC Controller单例和多例

    对于SpringMVC Controller单例和多例,下面举了个例子说明下. 第一次:类是多例,一个普通属性和一个静态属性. 结果:普通属性:0.............静态属性:0 普通属性:0. ...

  9. SpringMVC Controller 单例 多例

    对于SpringMVC 的Controller单例还是多例.下面举例说明:第一次:类是多例,类里包含一个普通属性,一个静态属性 结果:普通属性:0.............静态属性:0 普通属性:0. ...

随机推荐

  1. Dictionary通过Value找到它的key

    private void GetDicKeyByValue() { Dictionary<string, string> dic = new Dictionary<string, s ...

  2. 练习2 H题 - 求数列的和

      Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description 数列的 ...

  3. php mysql PDO使用

    <?php $dbh = new PDO('mysql:host=localhost;dbname=access_control', 'root', ''); $dbh->setAttri ...

  4. Streams and .NET

    http://www.codeguru.com/csharp/csharp/cs_data/streaming/article.php/c4223/Streams-and-NET.htm In thi ...

  5. Java传递程序员变量

            解决方案虽然简单,不过若是想不起来就麻烦啦,好方法往往简单.         1.如何在一个java文件叫A里用另一个java文件叫B的方法叫method()?             ...

  6. 深入了解一下PYTHON中关于SOCKETSERVER的模块-A

    有了这块知识,应该对各类WEB框架有更好的理解吧..FLASK,DJANGO,WEBPY.... #!/usr/bin/env python from BaseHTTPServer import HT ...

  7. WINDOWS下简单操作SQLITE3

    有测试操作的时候,还是很好的说~~~ 找个sqlite3.txt下载 sqlite3.exe db.sqlite3 SQLite version 3.7.13 2012-06-11 02:05:22 ...

  8. 【HDU3948】 The Number of Palindromes (后缀数组+RMQ)

    The Number of Palindromes Problem Description Now, you are given a string S. We want to know how man ...

  9. Ubuntu下su:authentication failure的解决办法

    $ su - rootPassword: su: Authentication failureSorry. 这时候输入 $ sudo passwd rootEnter new UNIX passwor ...

  10. 第1章 开发环境安装和配置(二)安装JDK、SDK、NDK

    原文 第1章 开发环境安装和配置(二)安装JDK.SDK.NDK 无论是用C#和VS2015开发Androd App还是用Java和Eclipse开发Androd App,都需要先安装JDK和Andr ...