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请求参数获取的几种方法 下面是我自己在使用时发现的,前辈们没有记录的细节和注意点 ...
随机推荐
- tensorRT使用python进行网络定义
- Mac开发博客摘录
https://blog.csdn.net/wangyouxiang/article/details/17855255 https://www.cocoacontrols.com/controls?p ...
- sed中支持变量的处理方法
1.eval sed ’s/$a/$b/’ filename2.sed "s/$a/$b/" filename3.sed ’s/’$a’/’$b’/’ filename 4.sed ...
- 如果是多个 c 代码的源码文件,编译方法如下: $ gcc test1.c test2.c -o main.out $ ./main.out test1.c 与 test2.c 是两个源代码文件。
如果是多个 c 代码的源码文件,编译方法如下: $ gcc test1.c test2.c -o main.out $ ./main.out test1.c 与 test2.c 是两个源代码文件.
- 转:Java中子类是否可以继承父类的static变量和方法而呈现多态特性
原文地址:Java中子类是否可以继承父类的static变量和方法而呈现多态特性 静态方法 通常,在一个类中定义一个方法为static,那就是说,无需本类的对象即可调用此方法,关于static方法,声明 ...
- 如何在win+r 或者是win10的应用搜索输入subl就能打开sublime
这虽然不是什么技术贴,我实在不想开启sublime还要动鼠标,或者输入subl长长的全称,这里有两种做法: 第一种 在环境变量添加sublime安装目录的变量,一般sublime的安装目录会有subl ...
- jquery代码修改input的value值,而页面上input框的值没有改变的解决办法
问题描述: 在搜索框中输入一些字符,并且点击搜索框右边的五角星做收藏操作时,打开的弹框中Save Search:后面的input中的值被赋值了外面搜索框的值,但是当此次操作完成之后,再次做同样的操作, ...
- inet超级服务器和守护进程
inetd是监视一些网络请求的守护进程,其根据网络请求来调用相应的服务进程来处理连接请求.它可以为多种服务管理连接,当 inetd接到连接时,它能够确定连接所需的程序,启动相应的进程,并把 socke ...
- 20180409 Code First
many people use DB First,Today I see Code First. 这部分,百度上面有更多详细的资料,虽然不明白Migrations内部的机制,但是还是可以记录一下 打 ...
- 20170724 Airflow官网资料学习
-- 1 Apache Airflow 文档 AirFlow 对编程人员来讲就是一个平台,用于进行日程安排和监控.但是还在卵化期,严格来说,不是一个完整的成品.