标签:
创建JavaBean
package com.itheima.domain; public class Person { private String name; private int age; private String sex; public Person() { super(); } public Person(String name, int age, String sex) { super(); this.name = name; this.age = age; this.sex = sex; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } }
jsp的useBean
其中id是对象名,class是类的完整路径,如果存在这个对象,则指向这个对象,如果不存在,则创建,如果存在这个对象时,标签中的内容不会输出,如果是新创建的对象,则执行标签中的内容
<%@ 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> <title>使用jsp标签</title> </head> <body> <!-- 实例化javaBean --> <jsp:useBean id="person" class="com.itheima.domain.Person"> heima: </jsp:useBean> <%=person.getName() %> </body> </html>
标签:
原文地址:http://www.cnblogs.com/lzzhuany/p/4713961.html