springMVC----springMVC的HelloWorld
来源:互联网 发布:kpmg 大数据招聘 编辑:程序博客网 时间:2024/05/22 06:51
搭建步骤
a.导入jar包
导入到spring4.0的所有jar包(虽然不是都有用的,但是我嫌麻烦就全导进来了)
b.配置web.xml----配置分发器
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!--设置第一个启动--> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping></web-app>
c.添加springmvc配置文件,默认在WEB-INF下配置[DispatcherServlet]-servlet.xml 文件
d.编写HelloController.java
@Override public ModelAndView handleRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception { ModelAndView mv = new ModelAndView(); //封装要显示到视图中的数据 mv.addObject("msg","hello springMVC"); //视图名 mv.setViewName("hello"); return mv; }e.编写springmvc-servlet.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" 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"> <!--配置handlerMapping--> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean> <!--配置handlerAdapter--> <bean class="org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter"></bean> <!--配置视图渲染器--> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property> <!--结果视图的前缀--> <property name="prefix" value="/WEB-INF/jsp"></property> <!--结果视图的后缀--> <property name="suffix" value=".jsp"></property> </bean> <!--如果没有配置adapter则需要将路径写完整,即/hello.do--> <bean id="/hello" class="cn.limbo.controller.HelloController" /></beans>
f.测试
0 0
- springMVC----springMVC的HelloWorld
- springMVC的HelloWorld
- SpringMVC的HelloWorld实现
- springMVC(1) 编写springMVC的HelloWorld
- springMVC-HelloWorld
- SpringMVC HelloWorld
- SpringMVC HelloWorld
- SpringMVC - HelloWorld
- springmvc helloworld
- springMVC helloworld
- 【SpringMVC】Helloworld
- 【springmvc】 springmvc 之 HelloWorld
- 第一节:springmvc的helloworld实例
- 基于SpringMVC的HelloWorld实现
- 自学-SpringMvc的HelloWorld-01
- 基于springMVC的HelloWorld实例
- 基于springMVC的HelloWorld实例
- helloworld,一个完整的springmvc入门demo
- 161007
- win7-64下Matlab2014配置安装SeDuMi_1.3及出现问题
- 排序算法(五类八种)
- Qt 并行框架参考资料和视频
- 【leetcode】123. Best Time to Buy and Sell Stock III
- springMVC----springMVC的HelloWorld
- CSS几个单词的意思
- (笔记)Spring实战_面向切面的Spring(1)_什么是面向切面编程
- Intel Code Challenge Final Round D Dense Subsequence(线段树)
- 银行家算法之安全性算法
- leetcode: 198. House Robber dp
- spring-reference-The IoC container的翻译笔记(自己用)
- 关于ListView的transcriptMode属性
- 文件载入。带盘符的绝对路径 与 './file.php' '../file.php' 'file.php'