SpringMVC.入门篇《二》form表单
SpringMVC.入门篇《二》form表单
项目工程结构:

在《springmvc入门篇一.HelloWorld》基础上继续添加代码,新增:FormController.java,form.jsp,formResult.jsp 三个文件,并修改了index.jsp文件
FormController.java
package com.charles.controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView; import com.charles.entity.Client; /**
* <p>Type: FormController</p>
* <p>Description: Form表单控制层</p>
* @author baitang.<gy03554>
* @date 2018年10月14日 下午4:37:08
* @version v1.0.0
*/
@Controller
public class FormController { @RequestMapping(value = "formpage", method = RequestMethod.GET)
public ModelAndView intoFormPage() { return new ModelAndView("form", "command", new Client());
} @RequestMapping(value = "register", method = RequestMethod.POST)
public String register(Model model, Client client) { String cemail = client.getCemail();
String cpwd = client.getCpwd(); System.out.println("客户输入的邮箱是:" + cemail);
System.out.println("客户输入的密码是:" + cpwd); model.addAttribute("cemail", cemail);
model.addAttribute("cpwd", cpwd);
return "formResult";
}
}
form.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>SpringMVC.入门篇《二》form表单</title>
</head> <body> <center>
<h2>客户注册</h2>
<form:form method="post" action="register"> <table border="1px" cellpadding="0" cellspacing="0">
<tr>
<td><form:label path="cemail">邮箱:</form:label> </td>
<td><form:input path="cemail"/> </td>
</tr>
<tr>
<td><form:label path="cpwd">密码:</form:label> </td>
<td><form:input path="cpwd"/> </td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="提交" />
</td>
<!-- <td></td> -->
</tr>
</table> </form:form>
</center>
</body>
</html>
formResult.jsp 代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!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>Insert title here</title>
</head> <body>
<center>
<h2>注册成功</h2>
<h3>邮箱:${cemail }</h3>
<h3>密码:${cpwd }</h3>
</center>
</body>
</html>
index.jsp 代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!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>Insert title here</title>
</head> <body>
<a href="hello">进入Hello页面.</a> <br/>
<a href="formpage">进入Form表单页面.</a> </body>
</html>
运行项目,通过浏览器访问:http://localhost:9826/springmvc ,点击:进入Form表单页面, 填写form表单信息,然后注册。



如有问题,欢迎纠正!!!
如有转载,请标明源处:https://www.cnblogs.com/Charles-Yuan/p/9786855.html
SpringMVC.入门篇《二》form表单的更多相关文章
- [精]Oracle APEX 5.0 入门教程(一) Form表单
Oracle APEX Tutorial for Beginners (APEX 5.0) 1- Introduction 2- Create Workspace 3- Work with Works ...
- springmvc使用map接收form表单的参数
其实只需要在map前面加上@RequestParam参数即可,jsp的name等都不变 public String queryByCondition(@RequestParam Map<Stri ...
- django form表单验证
一. django form表单验证引入 有时时候我们需要使用get,post,put等方式在前台HTML页面提交一些数据到后台处理例 ; <!DOCTYPE html> <html ...
- Unit 2.前端之html--table(表格),form(表单)标签
一.table标签 作用:定义html表格.一个table标签元素至少包含 thead(表头),tbody(表主题),还可以有tfoot(表底部) html表格游table元素及一个或者多个tr,th ...
- 前端HTML基础之form表单
目录 一:form表单 1.form表单功能 2.表单元素 二:form表单搭建(注册页面) 1.编写input会出现黄色阴影问题 三:完整版,前端代码(注册页面) 四:type属性介绍 1.inpu ...
- 天河微信小程序入门《四》:融会贯通,form表单提交数据库
天河在阔别了十几天之后终于又回来了.其实这篇文章里的demo是接着(天河微信小程序入门<三>)后面就做了的,但是因为最近在做别的项目,所以就偷懒没有发出来.放到今天来看,从前台提交数据到数 ...
- form表单那点事儿(下) 进阶篇
form表单那点事儿(下) 进阶篇 上一篇主要温习了一下form表单的属性和表单元素,这一片主要讲解用JavaScript如何操作form. 目录: 表单操作 取值 赋值 重置 校验 提交 技巧 不提 ...
- form表单那点事儿(上) 基础篇
form表单那点事儿(上) 基础篇 做为html中最为常见,应用最广泛的标签之一,form常伴随前端左右.了解更深,用的更顺. 目录: 表单属性 表单元素 常识 模拟外观 表单属性 这个表单展示了fo ...
- SpringMVC中使用bean来接收form表单提交的参数时的注意点
这是前辈们对于SpringMVC接收表单数据记录下来的总结经验: SpringMVC接收页面表单参数 springmvc请求参数获取的几种方法 下面是我自己在使用时发现的,前辈们没有记录的细节和注意点 ...
随机推荐
- linux状态及原理全剖析
Table of Contents 1 linux 1.1 proc filesystem 1.1.1 /proc 1.1.1.1 /proc/meminfo 1.1.1.2 /proc/stat 1 ...
- Chap3:区块链的衍生技术[《区块链中文词典》维京&甲子]
- <大话设计模式>工厂模式,策略模式
第一章:工厂模式: 通过封装,继承,多态解耦合 业务逻辑和界面逻辑分开 用单独的类创造实例,工厂:创造实例 工厂模式还可以用反射来实现,nsstringFromClass UML类图 聚合表示一众弱的 ...
- iOS只给矩形两个边加圆角
- (void)updataTopCornerRadius { CGRect clipRect = CGRectMake(, , self.headPhotoIv.width, self.headPh ...
- scala-数组/列表
import scala.collection.mutable.ArrayBuffer var ary=Array(1,2,3) println(ary.mkString) println(ary(1 ...
- python之文件操作示例
方法一: with open("e:\\gloryroad.txt","a+",encoding="utf-8") as file: fil ...
- Redis所支持的数据结构
1.启动Redis2.Redis所支持的数据结构 2.1.Redis常用操作 2.2.String类型及操作 2.3.Hash类型及操作 2.4.List类型及操作 2.5.Set类型及操作 2.6. ...
- 火币网API文档——REST API 签名认证
安全认证 目前关于apikey申请和修改,请在“账户 - API管理”页面进行相关操作.其中AccessKey为API 访问密钥,SecretKey为用户对请求进行签名的密钥(仅申请时可见).Pro站 ...
- 装系统w7、ubuntu、centos等系统(一)
装w7系统准备 1.从老毛桃u盘启动盘制作工具_老毛桃u盘装系统_老毛桃pe_老毛桃官网下载装机版 2.一个正常使用的U盘,但容量大于4G,并且插入电脑保持连接 3.老毛桃装机版选择U盘启动-> ...
- Nginx解析PHP的原理 | CGI、FastCGI及php-fpm的关系
Nginx解析PHP的原理,CGI/FastCGI以及PHP-Fpm的关系. 一.PHP+Nginx应运而生的场景.随着互联网的发展,用户对此接受面广,数据流的增大使得Web端的运行承载压力日益增大, ...