Springmvc搭建简单测试demo

创建第一个简单springmvc步骤。

(一)首先配置好jdk、tomcat。

(二)导入jar包

 

(三)添加配置文件:springmvc.xml

 

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

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

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

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

   xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd

      http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsd

      http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

 

   <!-- 配置自定扫描的包 -->

   <context:component-scanbase-package="com.atguigu.springmvc"></context:component-scan>

 

   <!-- 配置视图解析器: 如何把 handler方法返回值解析为实际的物理视图 -->

   <beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver">

      <propertyname="prefix"value="/WEB-INF/views/"></property>

      <propertyname="suffix"value=".jsp"></property>

   </bean>

  

   <!-- 配置视图  BeanNameViewResolver解析器:使用视图的名字来解析视图 -->

   <!-- 通过 order 属性来定义视图解析器的优先级, order值越小优先级越高 -->

   <beanclass="org.springframework.web.servlet.view.BeanNameViewResolver">

      <propertyname="order"value="100"></property>

   </bean>

  

   <!-- 配置国际化资源文件 -->

   <beanid="messageSource"

      class="org.springframework.context.support.ResourceBundleMessageSource">

      <propertyname="basename"value="i18n"></property>  

   </bean>

  

   <!-- 配置直接转发的页面 -->

   <!-- 可以直接相应转发的页面, 而无需再经过 Handler 的方法.  -->

   <mvc:view-controllerpath="/success"view-name="success"/>

  

   <!-- 在实际开发中通常都需配置 mvc:annotation-driven标签 -->

   <mvc:annotation-driven></mvc:annotation-driven>

</beans>

 

(四)配置web文档

 

 

<?xmlversion="1.0"encoding="UTF-8"?>

<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="WebApp_ID"version="3.0">

 <display-name>SpringMVC_Demo0621a</display-name>

 <welcome-file-list>

   <welcome-file>index.html</welcome-file>

   <welcome-file>index.htm</welcome-file>

   <welcome-file>index.jsp</welcome-file>

   <welcome-file>default.html</welcome-file>

   <welcome-file>default.htm</welcome-file>

   <welcome-file>default.jsp</welcome-file>

 </welcome-file-list>

 

 <servlet>

      <servlet-name>

         dispatcherServlet

      </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>-->

         <param-value>/WEB-INF/springmvc.xml</param-value>

      </init-param>

      <load-on-startup>1</load-on-startup>

   </servlet>

 

 <!-- 配置 org.springframework.web.filter.HiddenHttpMethodFilter:可以把 POST请求转为 DELETE POST 请求 -->

   <filter>

         <

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值