javaBean+EL表达式实现页面输出
1;javaBean
package com.study;
public class Person {
private String name;
private int age;
public Person() {
super();
}
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;
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<jsp:useBean id="person" class="com.study.Person" scope="request"/><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
2;jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>EL表达式</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<jsp:setProperty name="person" property="name" value="张三"/>
<jsp:setProperty name="person" property="age" value="19"/>
姓名:<%=person.getName()%>
年龄:<%=person.getAge()%><br/>
姓名:${person.getName()}
年龄:${person.getAge()}<br/>
姓名:<jsp:getProperty name="person" property="name"/>
年龄:<jsp:getProperty name="person" property="age"/>
</body>
</html>
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。