springmvc使用步骤

springmvc使用步骤:
1.导入jar包
spring-web-mvc
spring-beans
spring-context
spring-core
spring-expression
spring-aop
spring-web
2.web.xml配置springmvc的核心的过滤器
<!--配置springmvc的核心类-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--指定springmvc配置文件的文件名和路径,加载springmvc配置文件-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
3.创建springmvc配置文件,配置bean和访问路径
<bean name="/helloSpringMVC" class="com.qyxy.controller.HelloSpringMVC" scope="prototype"></bean>

4.创建springmvc的controller类和方法
public class HelloSpringMVC implements Controller {
public ModelAndView handleRequest(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws Exception {
System.out.println("hello springmvc -----");
return null;
}
}

5.测试:
http://localhost:8080/helloSpringMVC

posted @ 2018-01-11 11:04  小松鼠。  阅读(166)  评论(0编辑  收藏  举报