1.項目的目錄結構圖:

2.web.xml

2.web.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
5 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
6
7
8 <!-- spring監聽器,監聽springMvc環境 -->
9 <listener>
10 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
11 </listener>
12 <!-- 加載spring的配置文件 -->
13 <context-param>
14 <param-name>contextConfigLocation</param-name>
15 <param-value>/WEB-INF/springmvc-servlet.xml</param-value>
16 </context-param>
17 <!-- 配置Spring MVC DispatcherServlet -->
18 <servlet>
19 <servlet-name>springmvc</servlet-name>
20 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
21 <load-on-startup>2</load-on-startup>
22 </servlet>
23 <servlet-mapping>
24 <servlet-name>springmvc</servlet-name>
25 <url-pattern>*.do</url-pattern>
26 </servlet-mapping>
27 </web-app>
2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
5 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
6
7
8 <!-- spring監聽器,監聽springMvc環境 -->
9 <listener>
10 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
11 </listener>
12 <!-- 加載spring的配置文件 -->
13 <context-param>
14 <param-name>contextConfigLocation</param-name>
15 <param-value>/WEB-INF/springmvc-servlet.xml</param-value>
16 </context-param>
17 <!-- 配置Spring MVC DispatcherServlet -->
18 <servlet>
19 <servlet-name>springmvc</servlet-name>
20 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
21 <load-on-startup>2</load-on-startup>
22 </servlet>
23 <servlet-mapping>
24 <servlet-name>springmvc</servlet-name>
25 <url-pattern>*.do</url-pattern>
26 </servlet-mapping>
27 </web-app>
3
1.下圖說明Spring MVC中請求被處理的過程:


Oracle:
|| 或 concat()
SQLServer:
+
MySQL:
CONCAT()
DB2:
|| 或 CONCAT()
|| 或 concat()
SQLServer:
+
MySQL:
CONCAT()
DB2:
|| 或 CONCAT()
示例:向學生表中添加記錄
1.MySQL:
String strDate = "2014-03-10";
1.MySQL:
<insert id="addStudent" parameterType="Student" keyProperty="id">
insert into student(id,name,birth,score)
values(#{id},#{name},#{birth},#{score});
<selectKey resultType="int" keyProperty="id">
SELECT
LAST_INSERT_ID() AS VALUE
</selectKey>
</insert>
2.SQLServer:
代碼如下:2.SQLServer:
<insert id="addStudent" parameterType="Student" keyProperty="id">
insert into student(name,birth,score)
values(#{#{name},#{birth},#{score});
<selectKey resultType="int" keyProperty="id">
SELECT STOCKIDSEQUENCE.NEXTVAL AS VALUE FROM DUAL
</selectKey>
</insert>
3.Oracle:
3.Oracle:
<insert id="addStudent" parameterType="Student" keyProperty="id">
insert into student(name,birth,score)
values(#{#{name},#{birth},#{score});
<selectKey resultType="int" keyProperty="id">
select @@identity as inserted
</selectKey>
</insert>
String strDate = "2014-03-10";
StringTokenizer st = new StringTokenizer(strDate, "-");
Date date = null;
date = new Date(Integer.parseInt(st.nextToken()));
搞定!
date = new Date(Integer.parseInt(st.nextToken()));
搞定!
Type: Status Report
Messsage: HTTP method GET is not supported by this URL
Description: The specified HTTP method is not allowed for the requested resource.
錯誤原因:
1.繼承自HttpServlet的Servlet沒有重寫對于請求和響應的處理方法:doGet或doPost等方法;默認調用父類的doGet或doPost等方法;
2.父類HttpServlet的doGet或doPost等方法覆蓋了你重寫的doGet或doPost等方法;
父類HttpServlet的doGet或doPost等方法的默認實現是返回狀態代碼為405的HTTP錯誤表示對于指定資源的請求方法不被允許。
解決方法:
1.子類重寫doGet或doPost等方法;
2.在你擴展的Servlert中重寫doGet或doPost等方法來處理請求和響應時 不要調用父類HttpServlet的doGet或doPost等方法,即去掉super.doGet(request, response)和 super.doPost(request, response)。
如果子類僅僅重寫的是doGet或doPost其中一個方法,而沒有另一個方法,也會報405錯誤
Messsage: HTTP method GET is not supported by this URL
Description: The specified HTTP method is not allowed for the requested resource.
錯誤原因:
1.繼承自HttpServlet的Servlet沒有重寫對于請求和響應的處理方法:doGet或doPost等方法;默認調用父類的doGet或doPost等方法;
2.父類HttpServlet的doGet或doPost等方法覆蓋了你重寫的doGet或doPost等方法;
父類HttpServlet的doGet或doPost等方法的默認實現是返回狀態代碼為405的HTTP錯誤表示對于指定資源的請求方法不被允許。
解決方法:
1.子類重寫doGet或doPost等方法;
2.在你擴展的Servlert中重寫doGet或doPost等方法來處理請求和響應時 不要調用父類HttpServlet的doGet或doPost等方法,即去掉super.doGet(request, response)和 super.doPost(request, response)。
如果子類僅僅重寫的是doGet或doPost其中一個方法,而沒有另一個方法,也會報405錯誤