springmvc入门程序
2017-05-11 14:15
162 查看
工程目录如图所示
步骤一:添加jar包
jar包如工程目录所示
步骤二:在web.xml文件里面配置DispatcherServlet
步骤三:在工程目录下面创建资源文件夹,命名为config,并在该目录下面创建springmvc.xml配置文件(如工程目录所示)
步骤四:在src目录下创建第一个控制器MyController,并创建视图文件hello.jsp(如工程目录所示)
该文件内容如下
步骤五:配置springmvc.xml文件,内容如下
步骤六:部署项目,调试程序
在地址栏输入url
http://localhost:8080/springmvc1/hello.action
结果如下
步骤一:添加jar包
jar包如工程目录所示
步骤二:在web.xml文件里面配置DispatcherServlet
<servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <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>*.action</url-pattern> </servlet-mapping>
步骤三:在工程目录下面创建资源文件夹,命名为config,并在该目录下面创建springmvc.xml配置文件(如工程目录所示)
步骤四:在src目录下创建第一个控制器MyController,并创建视图文件hello.jsp(如工程目录所示)
该文件内容如下
package com.yyf.test; 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 MyController implements Controller { @Override public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception { // TODO Auto-generated method stub ModelAndView modelAndView=new ModelAndView(); modelAndView.setViewName("hello"); return modelAndView; } }
步骤五:配置springmvc.xml文件,内容如下
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" 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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 配置handler --> <bean name="/hello.action" class="com.yyf.test.MyController"></bean> <!-- 处理器映射器 --> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> <!-- 处理器适配器 --> <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /> <!-- 视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name = "prefix" value="/WEB-INF/jsp/"></property> <property name = "suffix" value = ".jsp"></property> </bean> </beans>
步骤六:部署项目,调试程序
在地址栏输入url
http://localhost:8080/springmvc1/hello.action
结果如下
相关文章推荐
- springmvc(一) 入门程序
- SpringMVC基础入门,创建一个HelloWorld程序
- Spring+SpringMVC+MyBatis深入学习及搭建(十三)——SpringMVC入门程序(二)
- springMVC框架--入门程序(一)
- SpringMVC基础入门,创建一个HelloWorld程序
- 简易的springmvc入门程序-springmvc框架的搭建
- 微信小程序开发结合现有SpringMvc-入门准备1
- springMVC入门程序-注解开发环境配置
- JavaWeb——springMVC入门程序
- 【Spring+SpringMVC+MyBatis深入学习及搭建】12.SpringMVC入门程序(一)
- SpringMVC-入门程序---IntelliJIDEA开发
- SpringMVC系列(一)SpringMVC概述和搭建SpringMVC的第一个helloWord入门程序
- springMVC注解开发入门程序
- SpringMvc一个简单的框架入门程序
- springMVC入门程序-非注解开发环境配置
- SpringMvc简单入门程序
- SpringMVC基础入门,创建一个HelloWorld程序
- 【Spring+SpringMVC+MyBatis深入学习及搭建】13.SpringMVC入门程序(二)
- SpringMVC入门程序
- SpringMVC简单地入门程序