通过javaaean输出用户信息
1、javabean代码
package lianxi; public class xinxi { private String name; private long num; private int age; private String address; public String getName() { return name; } public void setName(String name) { this.name = name; } public long getNum() { return num; } public void setNum(long num) { this.num = num; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } }
2、用户注册代码
<%@ 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> <form action="yonghu.jsp" method="post"> 姓名:<input type="text" name="name"><br> 性别:<input type="text" name="xingbie"><br> 年龄:<input type="text" name="nianling"><br> <input type="submit" value="提交信息"> </form> </body> </html>
3、输出信息代码
<%@ 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> <%request.setCharacterEncoding("UTF-8"); %> <jsp:useBean id="lianxi4" class="lianxi.lianxi4" scope="page"> <jsp:setProperty property="*" name="lianxi4"/></jsp:useBean> 姓名:<jsp:getProperty property="name" name="lianxi4"/><br> 性别:<jsp:getProperty property="xingbie" name="lianxi4"/><br> 年龄:<jsp:getProperty property="nianling" name="lianxi4"/> </body> </html>
4、运行结果