springMVC第一天
这些是springMVC3.2所用到的jar包
web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns: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/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>springmvcfirst1208</display-name> <!-- springmvc前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- contextConfigLocation配置springmvc加载的配置文件(配置处理器映射器、适配器等等)
如果不配置contextConfigLocation,默认加载的是/WEB-INF/servlet名称-serlvet.xml(springmvc-servlet.xml)
-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet> <servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping> <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>
</web-app>
上面我讲配置文件放在classpath下面,在项目件文件夹的时候要注意要选择新建source folder;如果新建文件夹的时候选择的是folder在调用url的时候就会提示找不到配置文件(找不到springmvc.xml)
springmvc.xml
<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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd "> <!-- 注解方式 适配器、解析器加载 -->
<mvc:annotation-driven></mvc:annotation-driven> <!-- 注解扫描制定的包路径 默认扫描com.mvc.controllter下的所有包含注解的类-->
<context:component-scan base-package="com.mvc.controller"></context:component-scan> <!-- 视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置jsp路径的前缀 -->
<property name="prefix" value="/WEB-INF/jsp/"/>
<!-- 配置jsp路径的后缀 -->
<property name="suffix" value=".jsp"/>
</bean>
</beans>
controllter代码,没有查数据
package com.mvc.controller; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; import com.mvc.model.Items; /***商品控制器*/
@Controller
@RequestMapping("/itemsController")
public class ItemsController { @RequestMapping("/queryItems")
public ModelAndView queryItems(){ List<Items> items=new ArrayList<Items>(); Items items_1 = new Items();
items_1.setName("小米note");
items_1.setPrice(6000f);
items_1.setDetail("ThinkPad");
items_1.setCreatetime(new Date()); Items items_2 = new Items();
items_2.setName("荣耀华为plus");
items_2.setPrice(5000f);
items_2.setDetail("荣耀华为plus");
items_2.setCreatetime(new Date()); items.add(items_1);
items.add(items_2); ModelAndView modelAndView=new ModelAndView();
modelAndView.addObject("items", items);
modelAndView.setViewName("items/itemsList"); return modelAndView;
}
}
前面springmvc.xml中将视图解析器的路径配置在/WEB-INF/jsp/下,文件名后缀为.jsp,所以对应的jsp路径就是/WEB-INF/jsp/items/itemsList.jsp
springMVC第一天的更多相关文章
- SpringMVC第一天(其他)
SpringMVC第一天 框架课程 课程计划 参数绑定 SpringMVC默认支持的类型 简单数据类型 Pojo类型 Pojo包装类型 自定义参数绑定 SpringMVC和Struts2的区别 高级参 ...
- springMVC 第一章
springMVC 第一章 一.分层结构的项目 组成方式: 表示层:页面,Servlet 业务层:业务逻辑类(service) 持久层:与数据库交互的类(dao) 程序执行的过程:表示层->se ...
- JAVAEE——SpringMVC第一天:介绍、入门程序、架构讲解、SpringMVC整合MyBatis、参数绑定、SpringMVC和Struts2的区别
1. 学习计划 第一天 1.SpringMVC介绍 2.入门程序 3.SpringMVC架构讲解 a) 框架结构 b) 组件说明 4.SpringMVC整合MyBatis 5.参数绑定 a) Sp ...
- springMVC第一天——入门、整合与参数绑定
大纲摘要: 1.Springmvc介绍 2.入门程序 3.Springmvc架构讲解 a) 框架结构 b) 组件说明 4.Springmvc整合mybatis 5.参数绑定 乱码问题解决 a) Spr ...
- springMVC第一课--配置文件
刚学springMVC,记录下学习过程,供以后查阅(githup源码). 1,新建一个web工程.(其他按常规来) 如下:添加applicationContext.xml,webmvc-servlet ...
- SpringMVC第一篇【介绍、入门、工作流程、控制器】
什么是SpringMVC? SpringMVC是Spring家族的一员,Spring是将现在开发中流行的组件进行组合而成的一个框架!它用在基于MVC的表现层开发,类似于struts2框架 为什么要使用 ...
- SpringMVC -- 第一个简单的程序
学习springMVC,我们来记录下第一个HelloWord的程序 首先.我们组织须要的jar包 commons-logging-1.1.3.jar spring-aop-4.1.7.RELEASE. ...
- SpringMVC 课程第一天
SpringMVC第一天 框架课程 1. 课程计划 第一天 1.SpringMVC介绍 2.入门程序 3.SpringMVC架构讲解 a) 框架结构 b) 组件说明 4.SpringMVC整合My ...
- 框架SpringMVC笔记系列 二 传值
主题:SpringMVC(第一节中再回顾复习一次) 学习资料参考网址: 1.http://www.icoolxue.com 2.http://haohaoxuexi.iteye.com/blog/13 ...
随机推荐
- Activity传递参数——传递简单数据
一.新建一个空的工程 二.在主界面中添加一个按钮 三.新建一个空的activity,并命名为TheAty 四.修改MainActivity.java中的onCreate函数 protected voi ...
- jsp中的session
浏览器和服务器的异常通话 常用方法 setAttribute(String key,Object value);//设置值 getAttribute(String key); //取值 Invalid ...
- (八)java运算符
算数运算符 + - * / % ++ -- class Ysf { public static void main(String[] args) { System.out.println(5/2);/ ...
- mysql-jdbc创建Statement与执行SQL
使用JDBC创建Connection后,执行SQL需要先创建Statement Statement stmt = connection.createStatement(); 创建代码如下 public ...
- 21天学通C++_Day2
继续学习,今天满课,相对学习内容较少,下面罗列内容: 0.常量 ▪字面常量: ▪使用关键字const声明的常量,const double Pi = 22.0/7; //后面有分号,跟定义变量一样 ▪使 ...
- 牛客国庆集训派对Day1:J:Princess Principal(栈模拟求括号匹配)
题目描述 阿尔比恩王国(the Albion Kingdom)潜伏着一群代号“白鸽队(Team White Pigeon)”的间谍.在没有任务的时候,她们会进行各种各样的训练,比如快速判断一个文档有没 ...
- Struts2 级联下拉框 详解析
目录(?)[+] 运行环境:myeclipse8.6+jboss5.1+jvm1.6 先看最后目录结构: 直接上源码: complexFormTag.jsp: <%@ page language ...
- [转]linux下查看进程内存使用情况
动态查看一个进程的内存使用 1.top命令 top -d 1 -p pid [,pid ...] //设置为delay 1s,默认是delay 3s 如果想根据内存使用量进行排序,可以shift + ...
- ansible安装基本使用
备注使用yum (centos7) 1. 安装 yum install -y ansible 2. 免密登录(ssh,最好使用dns 解析) // create ssh key ssh-keyge ...
- Ubantu 新建用户后没有生成对应文件夹
原命令:useradd python 改正后:useradd python -m 后成功在home目录下创建文件夹 原因: man useradd就可以看到如此介绍:Create the user´s ...