03---javabean03(设置与取得属性)
来源:互联网 发布:中国乡村 萧公权知乎 编辑:程序博客网 时间:2024/06/10 02:44
1、设置属性:<jsp:setProperty>
<jsp:setProperty>标签一共有四种使用方法:
·自动匹配:<jsp:setProperty name="实例化对象名称" property="*"/>
·指定属性:<jsp:setProperty name="实例化对象名称" property="属性名称"/>
·指定参数:<jsp:setProperty name="实例化对象名称" property="属性名称" param="参数名称"/>
·指定内容:<jsp:setProperty name="实例化对象名称" property="属性名称" value="内容"/>
指定属性:
input_bean02.html:
<html>
<body>
<form action="input_bean02.jsp" method="post">
姓名:<input type="text" name="name"><br>
年龄:<input type="text" name="age"><br>
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
</body>
</html>
input_bean02.jsp:
<%@ page contentType="text/html" pageEncoding="gbk"%>
<html>
<head><title>这是测试</title></head>
<body>
<%
request.setCharacterEncoding("gbk");
%>
<jsp:useBean id="simple" scope="request" class="org.lid.demo.SimpleBean"/>
<jsp:setProperty name="simple" property="name"/>
<jsp:setProperty name="simple" property="age"/>
<h3>姓名:<%=simple.getName()%></h3>
<h3>年龄:<%=simple.getAge()%></h3>
</body>
</html>
指定参数:
如果希望将那么参数的内容设置给age,而将age的内容设置给name,则此可以通过param进行指定;
<%@ page contentType="text/html" pageEncoding="gbk"%>
<html>
<head><title>这是测试</title></head>
<body>
<%
request.setCharacterEncoding("gbk");
%>
<jsp:useBean id="simple" scope="request" class="org.lid.demo.SimpleBean"/>
<jsp:setProperty name="simple" property="name" param="age"/>
<jsp:setProperty name="simple" property="age" param="name"/>
<h3>姓名:<%=simple.getName()%></h3>
<h3>年龄:<%=simple.getAge()%></h3>
</body>
</html>
指定内容:
<%@ page contentType="text/html" pageEncoding="gbk"%>
<html>
<head><title>这是测试</title></head>
<body>
<%
request.setCharacterEncoding("gbk");
int age=30;
%>
<jsp:useBean id="simple" scope="request" class="org.lid.demo.SimpleBean"/>
<jsp:setProperty name="simple" property="name" value="lid"/>
<jsp:setProperty name="simple" property="age" value="<%=age%>"/>
<h3>姓名:<%=simple.getName()%></h3>
<h3>年龄:<%=simple.getAge()%></h3>
</body>
</html>
2、取得属性<jsp:getProperty>:
在javabean的操作标签中也提供了专门的取得属性的标签:
<jsp:getProperty>,此标签会自动调用javabean中的getter()方法,与设置属性的标签相比,
取得属性的标签只有一种语法:
<jsp:getProperty name="实例化对象的名称" property="属性名称"/>
<%@ page contentType="text/html" pageEncoding="gbk"%>
<html>
<head><title>这是测试</title></head>
<body>
<%
request.setCharacterEncoding("gbk");
%>
<jsp:useBean id="simple" scope="request" class="org.lid.demo.SimpleBean"/>
<%--设置属性--%>
<jsp:setProperty name="simple" property="*"/>
<%--得到属性--%>
<h3>姓名:<jsp:getProperty name="simple" property="name"/></h3>
<h3>年龄:<jsp:getProperty name="simple" property="age"/></h3>
</body>
</html>
这种操作肯定也使用了反射机制完成,因为标签靠的就是反射机制;
当以后在一个jsp页面中在一个看不到<%%>之后,基本上jsp的标准开发模式就形成了;
注意以后一般在jsp标签(<jsp:**>)中只要看到id属性,不管何种情况,基本上就是表示一个实例化对象,
如果看到name属性,则肯定是找属性范围上的内容,即id指定的对象;而property则指的是
类中的一个属性;
- 03---javabean03(设置与取得属性)
- JavaBean设置与取得属性
- Android SystemProperties设置/取得系统属性
- Android SystemProperties设置/取得系统属性的用法总结(转)
- C# 遍历控件或类的属性(设置取得)其值
- VC++设置与取得系统音量
- VC++设置与取得系统音量
- 怎样用js取得/设置表格的所有属性?
- Android SystemProperties设置/取得系统属性的用法总结
- Android SystemProperties设置/取得系统属性的用法总结
- 设置和取得HTML标签的样式或属性值
- Android SystemProperties设置/取得系统属性的用法总结
- Android SystemProperties设置/取得系统属性的用法总结
- Android SystemProperties设置/取得系统属性的用法总结
- Android SystemProperties设置/取得系统属性的用法总结
- Android SystemProperties设置/取得系统属性的用法总结
- Android SystemProperties设置/取得系统属性的用法总结
- Android SystemProperties设置/取得系统属性的用法总结
- http抓包脚本
- 03---javabean01(javabean的简介及属性)
- 新浪旧事-checkstyle插件
- 03---javabean02(javabean与表单)
- NS3 -- 使用 socket
- 03---javabean03(设置与取得属性)
- 新浪旧事-ant+xdoclet1.2.3生成hibernate配置文件
- hadoop streaming 脚本格式错误
- 03---javabean04(javabean的保存范围)
- 03---javabean05(javabean的删除)
- Jquery 获得Form下的所有text、checkbox等表单的值
- 03---javabean06(注册验证)
- hibernate 多继承实体配置
- 新浪旧事-SSH之annotation