2 dong home dong_home 于 2014.03.03 16:14 提问

SpringMVC的搭建问题,求高手为小弟看看!

刚学习SpringMVC,想试着做个Demo出来。
springMVCTemplet-servlet.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀,这里以jsp为后缀名-->

</bean>
<!--告诉spring在cn.lym.control包下应用了spring注解  
    <context:component-scan base-package="com.controller" />
-->


web.xml配置如下:

<servlet>
    <servlet-name>springMVCTemplet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>springMVCTemplet</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

Controller如下
@Controller
public class TestSpringMvc {
@RequestMapping("/index.do")
public ModelMap testSpring(HttpServletRequest request,HttpServletResponse response){
ModelMap map=new ModelMap();
map.addAttribute("hello", "hello SpringMVC!!!");
return map;
}
}
jsp页面如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


Csdn user default icon
上传中...
上传图片
插入图片