码迷,mamicode.com
首页 > 编程语言 > 详细

EL在javabean中的使用

时间:2015-02-18 18:46:25      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:

Box.java:

package com.cuit.xywei.box;

public class Box {
long length=01;
long width=01;
long height=01;
public long getLength() {
return length;
}
public void setLength(long length) {
this.length = length;
}
public long getWidth() {
return width;
}
public void setWidth(long width) {
this.width = width;
}
public long getHeight() {
return height;
}
public void setHeight(long height) {
this.height = height;
}
public long getArea(){
return (length*width+length*height+width*height)*2;
}
public long getVolumn(){
return (length*width*height);
}

}

 

useBox.jsp:

<%@page import="com.cuit.xywei.box.Box"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>用EL使用JavaBean</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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<%
//生成一个javabean
com.cuit.xywei.box.Box box = new com.cuit.xywei.box.Box();
box.setLength(10);
box.setWidth(20);
box.setHeight(30);
request.setAttribute("box", box);
%>
盒子的表面积为:${box.area }
<br>
<c:set var="volumn" value="volumn" />
盒子的容积为:${box[volumn]}
</body>
</html>

这里有个地方不明白,为什么在这里:<c:set var="volumn" value="volumn" />
还有这里:盒子的容积为:${box[volumn]},var的变量的值不是value里面的volumn吗,为什么会变成真正的体积?两句如果改为:${box.volumn}的话也可以正确输出体积的。

EL在javabean中的使用

标签:

原文地址:http://www.cnblogs.com/listentothecloud20150215/p/4295879.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!