您的位置:首页 > 编程语言 > Java开发

Spring环境

2015-10-18 23:14 453 查看

1、 Spring官方网站下载Spring jar包

可以直接在地址栏用下面的地址找到树形结构,然后选择自己需要的资料:http://repo.springsource.org/libs-release-local/org/springframework/

2、Spring 环境搭建

web.xml

[code]<?xml version="1.0" encoding="utf-8"?>
<web-app id="WebApp_ID" version="2.4"
   xmlns="http://java.sun.com/xml/ns/j2ee" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
   <display-name>Spring MVC Application</display-name>

   <servlet>
  <servlet-name>MyWeb</servlet-name>
  <servlet-class>
 org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
 <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
   </servlet>

   <servlet-mapping>
  <servlet-name>MyWeb</servlet-name>
  <url-pattern>/</url-pattern>
   </servlet-mapping>
</web-app>


spring-mvc.xml

[code]<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans-4.2.xsd    http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-4.2.xsd     http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">     <mvc:annotation-driven/>
   <context:component-scan base-package="com.myweb" />

   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/" />
  <property name="suffix" value=".jsp" />
   </bean>
</beans>


helloController.java

[code]package com.myweb;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/hello")
public class HelloController{ 

    @RequestMapping(value="/myindex",method=RequestMethod.GET)
    public String index() {
  System.out.println("======wanghao : in");
        return "index";
    }
}


今日任务

1、成功搭建Spring环境

2、用java代码下载服务器文件

周末计划

1、完成下载文件的代码编写,并且成功下载文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: