JavaBean的使用和作用范围

在这里插入图片描述
使用规则:
在这里插入图片描述在这里插入图片描述
例如:在这里插入图片描述
传值和获取值的方法
<%@ page language=“java” contentType=“text/html;
charset=UTF-8”
pageEncoding=“UTF-8”%>
<%
request.setCharacterEncoding(“UTF-8”);

response.setContentType("text/html;charset=UTF-8");

%>

jsp:useBean标签使用范例3 //使用useBean声明 作用范围为page
<form action="" method="post">
<p>
		输入所有参数:<br> 姓名:<input type=text name="name" value="张洪"><br>       //value为默认值
		性别:<input type=text name="sex" value="女"><br> 年龄:<input
			type=text name="age" value="25"><br> <input type=submit
			value="提交">
</form>
<jsp:setProperty property="*" name="person" />
<h2>
	姓名:<jsp:getProperty property="name" name="person" /></h2>
<h2>
	性别:<jsp:getProperty property="sex" name="person" /></h2>
<h2>
	年龄:<jsp:getProperty property="age" name="person" /></h2>
运行效果如下: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190610160006309.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzIzMjQyMw==,size_16,color_FFFFFF,t_70)

猜你喜欢

转载自blog.csdn.net/weixin_43232423/article/details/91381342