国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

Spring MVC 開發(fā)快速入門

2019-11-18 13:38:05
字體:
來源:轉載
供稿:網(wǎng)友

  這篇文章將教你快速地上手使用 SPRing 框架,假如你手上有一本《Spring in Action》, 那么你最好從第三部分"Spring 在 Web 層的應用--建立 Web 層"開始看, 否則那將是一場惡夢!

  首先, 我需要在你心里建立起 Spring MVC 的基本概念. 基于 Spring 的 Web 應用程序接收到 http://localhost:8080/hello.do(事實上請求路徑是 /hello.do) 的請求后, Spring 將這個請求交給一個名為 helloController 的程序進行處理, helloController 再調用 一個名為 hello.jsp 的 jsp 文件生成 Html 代碼發(fā)給用戶的瀏覽器顯示. 上面的名稱(/hello.do, helloController, hello.jsp) 都是變量, 你可以更改.

  在 Spring MVC 中, jsp 文件中盡量不要有 java 代碼, 只有 HTML 代碼和"迭代(forEach)"與"判定(if)"兩個jstl標簽. jsp 文件只作為渲染(或稱為視圖 View)模板使用.

  好了, 我們開始吧. 首先我們需要一個放在 WEB-INF 目錄下的 web.xml 文件:

web.xml:
 1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
6 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
7
8 <context-param>
9 <param-name>contextConfigLocation</param-name>
10 <param-value>
11 /WEB-INF/database.xml
12 /WEB-INF/applicationContext.xml
13 </param-value>
14 </context-param>
15
16 <listener>
17 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
18 </listener>
19
20 <filter>
21 <filter-name>encodingFilter</filter-name>
22 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
23 <init-param>
24 <param-name>encoding</param-name>
25 <param-value>UTF-8</param-value>
26 </init-param>
27 </filter>
28
29 <filter-mapping>
30 <filter-name>encodingFilter</filter-name>
31 <url-pattern>*.do</url-pattern>
32 </filter-mapping>
33
34 <servlet>
35 <servlet-name>ideawu</servlet-name>
36 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
37 <load-on-startup>1</load-on-startup>
38 </servlet>
39
40 <servlet-mapping>
41 <servlet-name>ideawu</servlet-name>
42 <url-pattern>*.do</url-pattern>
43 </servlet-mapping>
44
45 <welcome-file-list>
46 <welcome-file>index.jsp</welcome-file>
47 <welcome-file>index.html</welcome-file>
48 </welcome-file-list>
49
50 <jsp-config>
51 <taglib>
52 <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
53 <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
54 </taglib>
55 <taglib>
56 <taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
57 <taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
58 </taglib>
59 </jsp-config>
60
61 </web-app>



發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 称多县| 洪洞县| 康平县| 五台县| 任丘市| 朔州市| 皋兰县| 泾川县| 西林县| 会宁县| 皋兰县| 西安市| 无棣县| 房产| 龙江县| 多伦县| 观塘区| 临高县| 威海市| 天等县| 福安市| 库伦旗| 财经| 长春市| 白河县| 洞头县| 儋州市| 黑水县| 永登县| 台湾省| 肃北| 东辽县| 孝昌县| 新竹县| 望奎县| 陆良县| 邓州市| 英吉沙县| 高邮市| 香河县| 图片|