spring mvc: 密码框
以user为例,包含username, password字段.
user.java
public class User {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
UserController.java代码
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.ui.ModelMap; @Controller
public class UserController { @RequestMapping(value = "/user", method = RequestMethod.GET)
public ModelAndView user() {
return new ModelAndView("user_index", "command", new User());
} @RequestMapping(value = "/addUser", method = RequestMethod.POST)
public String addUser(@ModelAttribute("SpringWeb")User user,
ModelMap model) {
model.addAttribute("username", user.getUsername());
model.addAttribute("password", user.getPassword()); return "user_add";
}
}
这里的第一个服务方法user(),我们已经在ModelAndView对象中传递了一个名称为“command”的空User对象,因为如果在JSP文件中使用<form:form>标签,spring框架需要一个名称为“command”的对象。 所以当调用user()方法时,它返回user.jsp视图。
第二个服务方法addUser()将根据URL => HelloWeb/addUser 上的POST方法请求时调用。根据提交的信息准备模型对象。 最后从服务方法返回“userlist”视图,这将呈现userlist.jsp视图。
user_index.jsp 的代码如下所示
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!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=utf-8">
<title>添加user信息</title>
</head>
<body> <form:form method="post" action="/hello/addUser">
<table>
<tr>
<td><form:label path="username">姓名:</form:label></td>
<td><form:input path="username" /></td>
</tr>
<tr>
<td><form:label path="password">密码</form:label></td>
<td><form:password path="password"/></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="提交表单"/>
</td>
</tr>
</table>
</form:form> </body>
</html>
user_add.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false" %>
<!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=utf-8">
<title>用户信息显示</title>
</head>
<body> <table>
<tr>
<td>用户名</td>
<td>${username}</td>
</tr>
<tr>
<td>密码</td>
<td>${password}</td>
</tr>
</table> </body>
</html>
如图:


spring mvc: 密码框的更多相关文章
- Spring MVC密码处理
以下示例显示如何在使用Spring Web MVC框架的表单中使用密码.首先使用Eclipse IDE来创建一个WEB工程,并按照以下步骤使用Spring Web Framework开发基于动态表单的 ...
- spring mvc:文本框
采用:<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> ...
- Spring MVC文本框
以下示例显示如何使用Spring Web MVC框架在表单中使用文本框.首先使用Eclipse IDE来创建一个Web工程,按照以下步骤使用Spring Web Framework开发基于动态表单的W ...
- spring mvc:常用标签库(文本框,密码框,文本域,复选框,单选按钮,下拉框隐藏于,上传文件等)
在jsp页面需要引入:<%@taglib uri="http://www.springframework.org/tags/form" prefix="form&q ...
- spring mvc:复选框(多选)
以user为例,user下有 username用户,password密码, address地址, receivePaper是否订阅, favotireFramework兴趣爱好, user.java ...
- Spring MVC列表多选框
以下示例显示如何在使用Spring Web MVC框架的表单中使用列表框(Listbox).首先使用Eclipse IDE来创建一个WEB工程,实现一个让用户可选择自己所善长的技术(多选)的功能.并按 ...
- Spring MVC复选框(多项)
以下示例显示如何在使用Spring Web MVC框架的表单中使用多个复选框(Checkbox).首先使用Eclipse IDE来创建一个WEB工程,并按照以下步骤使用Spring Web Frame ...
- Spring MVC复选框
以下示例显示如何在使用Spring Web MVC框架的表单中使用复选框(Checkbox).首先使用Eclipse IDE来创建一个WEB工程,并按照以下步骤使用Spring Web Framewo ...
- Spring MVC-表单(Form)标签-密码框(Password)示例(转载实践)
以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_password.htm 说明:示例基于Spring MVC 4.1.6. 以下示 ...
随机推荐
- PHP中Trait详解及其应用
w PHP中Trait详解及其应用 - 开发者日常 - SegmentFaulthttps://segmentfault.com/a/1190000008009455
- ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry ’1′ for key
当我用SQLyog尝试修改已有记录的mysql数据表的主键为自动增长时,报出以下错误 ALTER TABLE causes auto_increment resequencing, resulting ...
- 请写出用于校验HTML文本框中输入的内容全部为数字的javascript代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html ...
- facebook 相似性搜索库 faiss
faiss 个人理解: https://github.com/facebookresearch/faiss 上把代码clone下来,make编译 我们将CNN中经过若干个卷积/激励/池化层后得到的激活 ...
- scrapy item
item item定义了爬取的数据的model item的使用类似于dict 定义 在items.py中,继承scrapy.Item类,字段类型scrapy.Field() 实例化:(假设定义了一个名 ...
- Django web 框架
目录 与Django的第一次见面 安装.文件解释与基本命令 Settings Models Views 路由系统 模板 Form表单 Cookie与Session CSRF防护
- jdk1.7 ArrayList源码浅析
参考:http://www.cnblogs.com/xrq730/p/4989451.html(借鉴的有点多,哈哈) 首先介绍ArrayList的特性: 1.允许元素为空.允许重复元素 2.有序,即插 ...
- Php ArrayIterator的几个常用方法
搜索商低..从php.net找到 ,自己翻译一下 总结在一起 rewind() 指针回到初始位置 valid() 判断数组当前指针下是否有元素 key() 数组键 ...
- 在python中有多少种运算符?解释一下算术运算符
在python中,我们有7种运算符:算术运算符.关系运算符.赋值运算符.逻辑运算符.位运算符.成员运算符.身份运算符 我们有7个算术运算符,能让我们对数值进行算术计算 1.加号(+),将两个值相加 2 ...
- s5_day2作业
# 1:编写for循环,利用索引遍历出每一个字符 # msg = 'hello egon 666' # for i in range(len(msg)): # print(i,msg[i]) # 2: ...