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

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

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

    專注成就輝煌

    專注java

    SpringMvc&Maven初級篇(一)

    開發(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的)。如果提示錯誤,可能需要在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自動生成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的話,會和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)目,然后啟動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 一江東水 閱讀(6121) 評論(0)  編輯  收藏


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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲精品国产专区91在线| 亚洲av永久无码精品国产精品| 亚洲一区二区三区乱码在线欧洲| 亚洲va中文字幕无码久久不卡 | 亚洲国产成人精品无码久久久久久综合 | 亚洲无砖砖区免费| 国产精品免费大片| 亚洲AV永久无码精品水牛影视| 免费的黄色的网站| 亚洲日韩中文在线精品第一| 麻豆亚洲AV永久无码精品久久| 在线看片免费人成视频播| 亚洲成av人片天堂网| 日本亚洲中午字幕乱码| 哒哒哒免费视频观看在线www | 亚洲AV无码成人精品区蜜桃| 99免费在线观看视频| 亚洲香蕉在线观看| 国产美女精品久久久久久久免费 | 美女视频黄频a免费| 四虎影视永久免费观看地址| 成人片黄网站色大片免费观看cn| 最近中文字幕mv免费高清视频7| 亚洲AV成人一区二区三区在线看| 国产a不卡片精品免费观看| 一级毛片视频免费| 免费国产高清视频| 国内精品99亚洲免费高清| 亚洲视频免费观看| 凹凸精品视频分类国产品免费| 成人无码区免费A∨直播| 亚洲精品在线电影| 国产一区二区三区在线免费| 99视频在线观看免费| 亚洲jjzzjjzz在线观看| 久久爰www免费人成| 国产精品亚洲综合久久| 久久久久国产亚洲AV麻豆| 国产四虎免费精品视频| 成年大片免费高清在线看黄| 久久久国产精品亚洲一区|