日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

springmvc基本配置

發布時間:2024/1/17 c/c++ 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springmvc基本配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.開發環境搭建,我用的是eclipse+tomcat7+jdk1.6,這部分不做介紹

2.新建工程,我新建的是dynamic web project 命名為springmvc1

3.導入jar包,我用的是springframework3.1.1,目前官網spring不能下載,我是下載的源文件,用ant編譯的。需要導入的jar包有:

?

4.編寫WEB-INF/web.xml如下:

<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"><display-name></display-name><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- springMVC 配置 --><servlet><description>spring mvc servlet</description><servlet-name>springMvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><description>spring mvc 配置文件</description><param-name>contextConfigLocation</param-name><param-value>classpath:spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><!-- 攔截以html為后綴的請求 --><servlet-mapping><servlet-name>springMvc</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping><session-config><session-timeout>10</session-timeout></session-config><welcome-file-list><welcome-file>/views/index.jsp</welcome-file></welcome-file-list> </web-app>

5.編寫spring-mvc.xml以及spring.xml文件

spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"><!-- 自動掃描controller包下的所有類,使其認為spring mvc的控制器 --><context:annotation-config /><context:component-scan base-package="com.rainbow.controller" /><!-- 啟動Spring MVC的注解功能,完成請求和注解POJO的映射 --><beanclass="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean><bean id="viewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/views" /><property name="suffix" value=".jsp" /></bean> </beans>

spring.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: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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"><!-- 引入屬性文件 --><context:property-placeholder location="classpath:database.properties" /><!-- 自動掃描controller,dao,service包(自動注入) --><context:annotation-config /><context:component-scan base-package="com.rainbow" /></beans>

6.編寫controller文件,在src目錄下建立package

package com.rainbow.controller;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping;@Controller public class TestController {@RequestMapping("/hello")public String hello(){return "/hello";} }

以上是簡單的java文件,

7.編寫視圖文件,hello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> Hello world! </body> </html>

8.run 項目, 我們輸入http://localhost:9090/springmvc1/hello.do便可以獲得hello world的頁面輸出,以上是spring最基本的配置。 目前并沒有顯示數據層的東西。

?

主要是給自己做一下記錄,防止忘記。

下一篇介紹,導入數據庫,以及hibernate。

?


?

這部分準備放spring原理相關的東西

?

轉載于:https://www.cnblogs.com/snail-tomorrow/p/3482025.html

總結

以上是生活随笔為你收集整理的springmvc基本配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。