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请求参数获取的几种方法 下面是我自己在使用时发现的,前辈们没有记录的细节和注意点 ...
随机推荐
- 半屏控制器,view: UIViewController+KNSemiModal
半屏控制器,view: UIViewController+KNSemiModal https://github.com/kentnguyen/KNSemiModalViewController
- 创建日志表记录DML操作和DDL操作
创建一个日志表,记录dept表的DML操作 create table dept_log(logid number,type varchar2(50),logdate date,deptno numbe ...
- jquery基础学习之动画篇(四)
一,动画效果 hide() show() 隐藏与显示 hide(options) 隐藏 对应display:none,有参数就会变成动画, $(document).click(function () ...
- 洛谷P4587 神秘数 [FJOI2016] 主席树
正解:主席树 解题报告: 先放下传送门QAQ 首先可以先思考如果只有一组询问,怎么解决 可以这么想,最开始一个数也麻油的时候能表示的最大的数是0嘛 然后先排个序,按顺序每次新加入一个数x,设加入这个数 ...
- Linux内核如何装载和启动一个可执行程序(转)
原文:http://www.cnblogs.com/petede/p/5351696.html 实验七:Linux内核如何装载和启动一个可执行程序 姓名:李冬辉 学号:20133201 注: 原创作品 ...
- 批量查询"_mget"
1.不同index的批量查询GET /_mget{ "docs":[{ "_index":"test_index1", "_typ ...
- 更改配置:远程访问gitlab的postgresql数据库
作为这篇文章的补充: 将gitlab中的postgresql数据库开通远程访问 https://www.cnblogs.com/andy9468/p/10609682.html 替代(二)中的2.3. ...
- IIS下实现帝国CMS搜索页伪静态
前面ytkah讲了apache下帝国CMS搜索页伪静态实现方法,网友说服务器是用IIS,那么IIS下如何实现帝国CMS搜索页伪静态呢?首先得先有URL重写插件,下载地址:http://www.iis. ...
- 自定义UIProgressView
自定义CustomporgressView #import <UIKit/UIKit.h> @interface CustomporgressView : UIView @property ...
- mysql命令行各个参数解释
mysql命令行各个参数解释 http://blog.51yip.com/mysql/1056.html Usage: mysql [OPTIONS] [database] //命令方式 -?, ...