你的位置:首页 > Java教程

[Java教程]springMVC部署


  一、导入springMVC说需要的jar包

     下载地址:http://repo.spring.io/release/org/springframework/spring/

      

二、springMVC框架配置

  1、web.

1 <servlet>2    <servlet-name>spring</servlet-name>3    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>4    <load-on-startup>1</load-on-startup>5  </servlet>6  <servlet-mapping>7    <servlet-name>spring</servlet-name>8    <url-pattern>*.do</url-pattern>9  </servlet-mapping>

 

  2、(在WebRoot/WEB-INF下)创建spring配置文件

  注意:此配置文件名称必须为 :servletName-servlet.

1     <!--1 MVC注解支持 -->2    <mvc:annotation-driven />3    <!--2 注解扫描目录-->4    <context:component-scan base-package="com.sxdx.hello"></context:component-scan>5    <!--3 处理静态文件 -->6    <mvc:default-servlet-handler />

  3、创建Controller控制器(Action) 

 1 package com.sxdx.hello; 2 import javax.servlet.http.HttpServletRequest; 3 import javax.servlet.http.HttpServletResponse; 4 import org.springframework.stereotype.Controller; 5 import org.springframework.web.bind.annotation.RequestMapping; 6 import org.springframework.web.servlet.ModelAndView; 7  8 @Controller 9 public class demo {10   @RequestMapping(value="/demo1")11   public String demo1(HttpServletRequest request,12         HttpServletResponse response){13     System.out.println("demo1===");14     return "";15   }16 }

   4、浏览器访问 http://localhost:8080/spring01/demo1.do 后台输出demo1===