Spring MVC如何获取文本密码框中的值呢?

Java-框架王 SpringMVC 发布时间:2021-07-11 15:02:55 阅读数:1625 1

下文讲述SpringMVC中获取文本密码框中值的方法分享,如下所示:
   1.创建一个动态Web工程
   2.创建一个实体类User及UserController类
   3.创建两个jsp页面
    4.运行Tomcat即可查看系统的运行情况


User实体类
 

    

package com.java265.helloworld.Entity;

public class User {

	private String userName;
	private String eMail;
	private String passWord;

	public User() {
		super();
	}

	public User(String userName, String eMail) {
		super();
		this.userName = userName;
		this.eMail = eMail;
	}

	public User(String userName, String eMail, String passWord) {
		super();
		this.userName = userName;
		this.eMail = eMail;
		this.passWord = passWord;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String geteMail() {
		return eMail;
	}

	public void seteMail(String eMail) {
		this.eMail = eMail;
	}

	public String getPassWord() {
		return passWord;
	}

	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}

}

创建一个UserController类,用于返回表单登记页面和表单信息接收页面

package com.java265.helloworld.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 com.java265.helloworld.Entity.User;

@Controller
public class UserController {

	/**
	 * 用户返回用户注册
	 *
	 */
	@RequestMapping(value = "/userReg", method = RequestMethod.GET)
	public String userReg() {

		return "userReg";
	}

	/**
	 * 
	 * 使用Spring MVC获取文本变量
	 * 
	 * @param userName      :此出的名字缺省情况下只需同表单中的name对应即可获取数值
	 * @param emailAddress: 同上
	 * 
	 * @return
	 */
	@RequestMapping(value = "/userReg", method = RequestMethod.POST)
	public String userReg(String userName, String emailAddress, String passWord, Model model) {

		System.out.print(userName);

		User u = new User(userName, emailAddress, passWord);
		model.addAttribute("u", u);

		return "showUserInfo";

	}

}


创建一个userReg.jsp页面

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

 <form action="/com.java265.helloworld/userReg"  method="post">
    userName:<input type="text"   name="userName" /><br />
    email:  <input type="text"    name="emailAddress" /><br />
    password:<input type="password"   name="passWord" /><br />
    
    <input type="submit" value="submit" />
    
 </form>
</body>
</html>


 

创建一个接收数据展示页面

 

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

java265.com--ShowUserInfo <br />
<hr />
userName: ${requestScope.u.userName}
 <br />
email:    ${requestScope.u.eMail} <br />

<br />
passWord:    ${requestScope.u.passWord} <br />


</body>
</html>

运行Tomcat即可查看项目的运行效果
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

本文链接: https://www.Java265.com/JavaFramework/SpringMVC/202107/458.html

最近发表

热门文章

好文推荐

Java265.com

https://www.java265.com

站长统计|粤ICP备14097017号-3

Powered By Java265.com信息维护小组

使用手机扫描二维码

关注我们看更多资讯

java爱好者