<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    專注成就輝煌

    專注java

    SpringMvc&Maven初級(jí)篇(一)

    開發(fā)工具:Eclipse IDE for Java EE Developers
    目標(biāo):使用SpringMvc框架和Maven配置,開發(fā)HelloWorld項(xiàng)目
    步驟:
    1.新建--Maven Project



    2.配置eclipse:
    右鍵項(xiàng)目,選擇Project Facets,點(diǎn)擊Convert to faceted from
    http://dl.iteye.com/upload/attachment/357986/90cb6af7-e66e-36f7-93dd-a8dbb809146e.png,
    更改Dynamic Web Module的Version為2.5。(3.0為Java7的)。如果提示錯(cuò)誤,可能需要在Java Compiler設(shè)置Compiler compliance level 為1.6。或者需要在此窗口的Java的Version改成1.6。
    http://dl.iteye.com/upload/attachment/357990/7146caa8-1652-3fbd-8cf1-4eff8d13933a.png,
    點(diǎn)擊Further configuration available…,彈出Modify Faceted Project窗口此處是設(shè)置web.xml文件的路徑,我們輸入src/main/webapp。Generate web.xml deployment descriptor自動(dòng)生成web.xml文件,推薦勾選。
    設(shè)置部署程序集(Web Deployment Assembly):
    http://dl.iteye.com/upload/attachment/357992/d8d75b79-e276-3e4b-a121-c172cb00f126.png
     Add -> Java Build Path Entries -> Maven Dependencies -> Finish

    設(shè)置完成效果圖
    http://dl.iteye.com/upload/attachment/357996/1def857e-b75a-35f3-ac0b-b7f1c42db7ec.png


    3.配置pom.xml:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>helloworld</groupId>
    <artifactId>helloworld</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>helloworld</name>
    <description>helloworld</description>

    <properties>
    <spring.version>3.0.5.RELEASE</spring.version>
    </properties>

    <dependencies>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>${spring.version}</version>
    </dependency>

    <!-- Other dependencies -->
    <dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.1</version>
    </dependency>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    </dependency>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.8.1</version>
    </dependency>
    </dependencies>
    </project>

    web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns
    ="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation
    ="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        id
    ="WebApp_ID" version="3.0">
        
    <display-name>helloworld</display-name>
        
    <servlet>
            
    <servlet-name>dispatcher</servlet-name>
            
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            
    <load-on-startup>1</load-on-startup>
        
    </servlet>

        
    <servlet-mapping>
            
    <servlet-name>dispatcher</servlet-name>
            
    <url-pattern>*.html</url-pattern>
        
    </servlet-mapping>
        
    <welcome-file-list>
            
    <welcome-file>index.html</welcome-file>
            
    <welcome-file>index.htm</welcome-file>
            
    <welcome-file>index.jsp</welcome-file>
            
    <welcome-file>default.html</welcome-file>
            
    <welcome-file>default.htm</welcome-file>
            
    <welcome-file>default.jsp</welcome-file>
        
    </welcome-file-list>
    </web-app>

    dispatcher-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:p="http://www.springframework.org/schema/p"
        xmlns:context
    ="http://www.springframework.org/schema/context"
        xmlns:mvc
    ="http://www.springframework.org/schema/mvc"
        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
        "
    >
        
        
    <!-- 搜索的控制類路徑(C) -->
        
    <context:component-scan base-package="com.myapps.controllers" />
        
        
    <!-- 配置視圖路徑(V) -->
        
    <bean id="viewResolver"    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            
    <property name="prefix" value="/WEB-INF/views/"/>
            
    <property name="suffix" value=".jsp"/>
        
    </bean>
    </beans>

    在WEB-INF下新建文件夾:views
    在views文件夾下新建

    helloworldPage.jsp
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding
    ="UTF-8"
    %>
    <!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=UTF-8">
    <title>helloworldPage.jsp</title>
    </head>
    <body>
    Hello,world.Welcome ${name} here.
    </body>
    </html>

    新建包:com.myapps.controllers

    在上面的包內(nèi)新建類:HelloWorldController.java



    package com.myapps.controllers;

    import
    org.springframework.stereotype.Controller;
    import
    org.springframework.web.bind.annotation.RequestMapping;
    import
    org.springframework.web.servlet.ModelAndView;

    @Controller
    public class
    HelloWorldController {


    @RequestMapping(value="/helloworld")

    public ModelAndView helloWord() {
    return new
    ModelAndView("helloworldPage", "name", "hdh");

    }

    }


     

    接著在webapp下新建index.htm(注意后綴是htm,因?yàn)槿绻莌tml的話,會(huì)和web.xml的<url-pattern>*.html</url-pattern>攔截的后綴名沖突,當(dāng)然也可以新建index.jsp文件)

    <!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=UTF-8"
    >
    <title>index.htm</title>
    </head>
    <body>
    <a href="helloworld.html">hello,world(htm)</a>
    </body>
    </html>


    最后,部署項(xiàng)目,然后啟動(dòng)tomcat服務(wù)器,輸入http://localhost:8080/helloworld/index.htm
    ,點(diǎn)擊鏈接進(jìn)行測試。這樣簡單的Hello,world入門就完成了。
    源碼下載地址:/Files/svygh123/helloworld.rar
    有不足的地方,請指正,有不明白的地方可以交流,謝謝。

    posted on 2012-06-02 23:57 一江東水 閱讀(6115) 評(píng)論(0)  編輯  收藏


    只有注冊用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲熟妇成人精品一区| 97碰公开在线观看免费视频| 亚洲熟女www一区二区三区| 亚洲中文字幕无码一区| 精品免费国产一区二区| 亚洲成年人免费网站| eeuss影院www天堂免费| 亚洲精品色播一区二区| 亚洲国产精品日韩在线观看| 亚洲国产精华液网站w| 亚洲精品视频免费观看| 日韩免费高清视频网站| 国产成人午夜精品免费视频| 一级毛片免费视频| 免费一区二区无码东京热| 一级毛片试看60分钟免费播放| 亚洲国产成人综合精品| 亚洲avav天堂av在线网爱情| 久久久久亚洲AV片无码| 亚洲人成亚洲人成在线观看| 亚洲国产精品成人久久蜜臀| 日韩免费视频播放| 日韩免费高清一级毛片在线| 男女交性永久免费视频播放 | 亚洲黄网站wwwwww| 亚洲AV无码不卡在线播放| 亚洲人成色7777在线观看| 亚洲最大激情中文字幕| 中文字幕亚洲日韩无线码| 国产成人高清亚洲| 亚洲色图综合在线| 国产成人精品亚洲精品| 久99精品视频在线观看婷亚洲片国产一区一级在线 | 国内精品免费视频自在线| 妞干网免费观看视频| 性感美女视频在线观看免费精品 | 亚洲视频网站在线观看| 亚洲男女性高爱潮网站| 亚洲av永久无码嘿嘿嘿| 亚洲欧美国产精品专区久久| 自拍偷自拍亚洲精品播放|