Maven项目SpringMVC环境搭建

Maven项目SpringMVC环境搭建

创建Maven项目(针对于Eclipse)(右击new-->选择other--->搜索 maven--->选择Maven project点击(Next)下一步创建项目)

 

点击Finish完成即可

 

1.导入jar

导入SpringMVC核心jar包

org.springframework

spring-context

4.3.18.RELEASE

 

org.springframework

spring-core

4.3.18.RELEASE

 

org.springframework

spring-web

4.3.18.RELEASE

 

org.springframework

spring-webmvc

4.3.18.RELEASE

 

javax.servlet

servlet-api

2.5

provided

2.修改配置web.xml

dispatcherServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:springmvc.xml

1

dispatcherServlet

/

3.创建测试类SpringController实现Controller接口重写handleRequest方法代码如下:

package com.znsd.springmvc.controller;

 

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

import org.springframework.web.servlet.ModelAndView;

import org.springframework.web.servlet.mvc.Controller;

 

public class SpringController implements Controller{

 

@Override

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

System.out.println("-------------SpringController------------");

return new ModelAndView("show.jsp");//跳转的页面

}

}

 

4.增加SpringMVC配置文件(springmvc.xml)

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:aop="http://www.springframework.org/schema/aop"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd">

 

 

5.创建一个index.jsp页面测试indexAction请求是否能进入show.jsp页面

 

你可能感兴趣的:(SpringMVC)