1.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name>
<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>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
2.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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<context:component-scan base-package="zou.huiying"></context:component-scan>
<bean class="org.springframework.web.servlet.mvc.support.ControllerBeanNameHandlerMapping" />
<bean name="hello.do" class="zou.huiying.Fcontroller"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
3.Fcontroller.java
package zou.huiying;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class Fcontroller {
@RequestMapping(value="/hello.do")
public String zouhuiying(String hello,Model model){
System.out.println(hello);
model.addAttribute("canshu", "hello"+hello);
System.out.println("dddddddddddddd");
return "aa";
}
}
4.index.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equive="Content-Type" content="text/html"; charset=utf-8 >
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="hello.do" method="post">
hello:<input type="text" name="hello" />
<input type="submit" value="tijiao" />
</form>
This is my JSP page. springmvc<br>
</body>
</html>
5.views/aa.jsp
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. <br>
<h1>${canshu }</h1>
</body>
</html>
错误笔记:
spring报错context不可识别 (springmvc-servlet.xml中)
在上下文中添加
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
上面文件已经配置好
分享到:
相关推荐
IT学习者Spring MVC注解实例.pdf
对spring mvc注解的实例
Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于...
主要介绍Spring MVC 的使用注解来配置的使用实例
能帮助到大家开发的使用文档.大家可以下下来看看,真的不错噢
spring3.0MVC注解(附实例). spring3.0MVC注解(附实例). spring3.0MVC注解(附实例).
spring mvc 注解 拦截器 对一个数据库表进行了增删改查操作 ,初学spring mvc框架的 可以参考 代码下载直接可以运行!~~ 包含jar和数据库sql语句
基于spring mvc注解的增删改实例,orm采用hibernate。 资源来自csdn,添加了修改功能和readme说明,让初学者更简单的运行起来。
这是一个Spring MVC实例 使用MVC注解配置
spring3.0mvc自学教程ppt+注解教程+注解实例+springmybatis教程+项目实例+中文api 初学(自学)着的不二法定,从入门到项目实例深入学习(浅-深)
学习Spring MVC,关于注解的Spring MVC,简单例子,关于控制器的Spring MVC,学习Spring,简单Spring MVC实例
详细描述springmvc开发及使用,注解开发的好处,及详细案例
spring3.0MVC注解(附实例)
Spring MVC基于注解完整实例,学习的好东西
Spring Mvc实例 主要实现利用spring注解,完成前后台交互,简单的视图控制和数据操作。
Spring mvc、 Spring、 Mybatis、 注解实例、 项目实例 从入门到项目实战
spring mvc 实例有数据库,jar包,代码之间还有详细的注解,特别适合初学者学习,之间导入myeclipse工程中就可以用.希望对初学者学习spring mvc框架有帮助.
Spring MVC 3实例,包含上传下载,还有Spring mvc jsr303表单验证技术,还有一个spring mvc ajax json等 欢迎下载 自己研究,简单易懂 如果有注解不懂,可以看看...