SpringMVC测试

来源:互联网 发布:mysql获取第一条记录 编辑:程序博客网 时间:2024/05/23 07:24


  一。webxml

   <!-- 注册springmvc核心控制器 -->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 通知DispatcherServlet去指定的目录下加载springmvc.xml配置文件 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>

二。spring.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:mvc="http://www.springframework.org/schema/mvc"

      xsi:schemaLocation="

 http://www.springframework.org/schema/beans 
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        
      ">
      
      
      <!-- 注册Action(必须配置) bean的ID不能名字相同,不然会报错的-->
      <bean name="hello.action" class="com.ts.demo.HeelloAction"></bean>
       <bean name="/demo.action" class="com.ts.demo.SpringDemo"></bean>

三 demo.jsp

  <%@ page language="java"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
 
${hello};
 ${message};
</body>
</html>

原创粉丝点击