HTML密码框

<td><form:label path="password">密码:</form:label></td>
<td><form:password path="password" /></td>

呈现HTML文本内容

 <td><form:label path="address">地址:</form:label></td>
<td><form:textarea path="address" rows="5" cols="30" /></td>

呈现HTML复选框

<td><form:label path="receivePaper">订阅新闻?</form:label></td>
<td><form:checkbox path="receivePaper" /></td>

呈现HTML单选框

<form:radiobutton path="gender" value="M" label="男" />
<form:radiobutton path="gender" value="F" label="女" />

多选单选按钮

<form:radiobuttons path="favoriteNumber" items="${numbersList}" />

下拉框

<tr>
<td><form:label path="country">所在国家:</form:label></td>
<td><form:select path="country">
<form:option value="NONE" label="请选择..." />
<form:options items="${countryList}" />
</form:select></td>
</tr>

Spring MVC隐藏字段域

<tr>
<td></td>
<td><form:hidden path="id" value="1000" /></td>
</tr>

错误处理

 <td><form:errors path="name" cssClass="error" /></td>

文件上传

package com.com.tanlei.Model;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.FileCopyUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView; import javax.servlet.ServletContext;
import java.io.File;
import java.io.IOException; @Controller
public class FileUploadController { @Autowired
ServletContext context; @RequestMapping(value = "/fileUploadPage", method = RequestMethod.GET)
public ModelAndView fileUploadPage(){
FileModel file=new FileModel();
ModelAndView modelAndView=new ModelAndView("fileUpload", "command", file);
return modelAndView;
} @RequestMapping(value="/fileUploadPage", method = RequestMethod.POST)
public String fileUpload(@Validated FileModel file, BindingResult result, ModelMap model){
if (result.hasErrors()){
System.out.println("validation errors");
return "fileUploadPage";
}else{
System.out.println("Fetching file");
MultipartFile multipartFile = file.getFile();
String uploadPath = context.getRealPath("") + File.separator + "temp" + File.separator;
//Now do something with file...
try {
FileCopyUtils.copy(file.getFile().getBytes(), new File(uploadPath+file.getFile().getOriginalFilename()));
} catch (IOException e) {
e.printStackTrace();
}
String fileName = multipartFile.getOriginalFilename();
model.addAttribute("fileName", fileName);
return "success"; } }
}
package com.com.tanlei.Model;

import org.springframework.web.multipart.MultipartFile;

public class FileModel {
private MultipartFile file; public MultipartFile getFile() {
return file;
} public void setFile(MultipartFile file) {
this.file = file;
}
}
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<title>Spring MVC上传文件示例</title>
</head>
<body>
<form:form method="POST" modelAttribute="fileUpload" enctype="multipart/form-data">
请选择一个文件上传 :
<input type="file" name="file" />
<input type="submit" value="提交上传" />
</form:form>
</body>
</html>
<%@ page contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title>Spring MVC上传文件示例</title>
</head>
<body>
文件名称 :
<b> ${fileName} </b> - 上传成功!
</body>
</html>

SpringMvc表单标签库的更多相关文章

  1. springmvc表单标签库的使用

    springmvc中可以使用表单标签库,支持数据绑定,用来将用户输入绑定到领域模型. 例子来源<Servlet.JSP和SpringMVC学习指南> 项目代码 关键代码及说明 bean对象 ...

  2. 关于Spring MVC中的表单标签库的使用

    普通的MVC设计模式中M代表模型层,V代表视图层,C代表控制器,SpringMVC是一个典型的MVC设置模式的框架,对于视图和控制器的优化很多,其中就有与控制器相结合的JSP的表单标签库. 我们先简单 ...

  3. (转载)SPRINGMVC表单标签简介

    SpringMVC表单标签简介 在使用SpringMVC的时候我们可以使用Spring封装的一系列表单标签,这些标签都可以访问到ModelMap中的内容.下面将对这些标签一一介绍. 在正式介绍Spri ...

  4. SpringMVC表单标签简介

    在使用SpringMVC的时候我们可以使用Spring封装的一系列表单标签,这些标签都可以访问到ModelMap中的内容.下面将对这些标签一一介绍. 在正式介绍SpringMVC的表单标签之前,我们需 ...

  5. Spring MVC 数据绑定和表单标签库

    数据绑定是将用户输入绑定到领域模型的一种特性.作用是将 POJO 对象的属性值与表单组件的内容绑定. 数据绑定的好处: 1. 类型总是为 String 的 HTTP 请求参数,可用于填充不同类型的对象 ...

  6. SpringMVC听课笔记(SpringMVC 表单标签 & 处理静态资源)

    1.springmvc表单标签,可以快速开发,表单回显,但是感触不深 2.静态资源的获取,主要是要配置这个

  7. SpringMVC 表单标签 & 处理静态资源

    使用 Spring 的表单标签 通过 SpringMVC 的表单标签可以实现将模型数据中的属性和 HTML 表单元素相绑定,以实现表单数据更便捷编辑和表单值的回显. form 标签 一般情况下,通过 ...

  8. SpringMVC 表单标签

    引入标签库 <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" ...

  9. SpringMVC表单标签

    SpringMVC学习系列(11) 之 表单标签   本篇我们来学习Spring MVC表单标签的使用,借助于Spring MVC提供的表单标签可以让我们在视图上展示WebModel中的数据更加轻松. ...

随机推荐

  1. 洛谷 P2886 [USACO07NOV]牛继电器Cow Relays

    题面 解题思路 ## floyd+矩阵快速幂,跟GhostCai爷打赌用不用离散化,最后完败..GhostCai真是tql ! 有个巧妙的方法就是将节点重新编号,因为与节点无关. 代码 #includ ...

  2. 图像复原MATLAB实现

    前言:本篇博客先介绍滤波器滤除噪声,再介绍滤波器复原,侧重于程序的实现. 一:三种常见的噪声 二:空间域滤波 空间域滤波复原是在已知噪声模型的基础上,对噪声的空间域进行滤波.空间域滤波复原方法主要包括 ...

  3. SpringData _day01_jpa的入门

    1.orm思想和以及jpa的概述和jpa的基本操作 简单的说:ORM就是建立实体类和数据库表之间的关系,从而达到操作实体类就相当于操作数据库表的目的. orm思想    主要目的:操作实体类就相当于操 ...

  4. redis教程(三)-----redis缓存雪崩、缓存穿透、缓存预热

    缓存雪崩 概念 缓存雪崩是由于原有缓存失效(过期),新缓存未到期间.所有请求都去查询数据库,而对数据库CPU和内存造成巨大压力,严重的会造成数据库宕机.从而形成一系列连锁反应,造成整个系统崩溃. 解决 ...

  5. win10文件名或文件路径过长导致无法删除或复制的解决办法

    试过了百度上的所有方法,命令行中del没有作用,Unlocker也没用,批处理也不起作用,360的强力删除也没有作用. 最后找到一种方法,在压缩该文件的时候选择删除源文件. 但是需要注意一点,用360 ...

  6. Spring BatchSqlUpdate.updateByNamedParam例子

    关键在于定义参数和sql语句,代码如下: int dstColCount=dstColNamesList.size(); String insSql="insert into "+ ...

  7. GULP入门之API(二)

    GULP的API gulp.src(globs[, options]) 输出(Emits)符合所提供的匹配模式(glob)或者匹配模式的数组(array of globs)的文件. 将返回一个 Vin ...

  8. storm 动态设置并发度

  9. getBoundingClientRect介绍

    getBoundingClientRect用于获取元素相对与浏览器视口的位置 由于getBoundingClientRect()已经是w3c标准,所以不用担心兼容,不过在ie下还是有所区别 { top ...

  10. PHP CURL header 设置HOST主机头进行访问并 POST提交數據

    $host = array("Host: act.qzone.qq.com");// 域名不帶http://$data = array(            'aa' => ...