JavaBean组件在JSP文档中的应用

Bean:

package cn.donghaua.bean;

public class StringBean {
private String message = "No message specificed";

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

}

StringBean.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>

<%
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>My JSP 'StringBean.jsp' starting page</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>
<jsp:useBean id="stringBean" class="cn.donghaua.bean.StringBean"/>
<jsp:setProperty property="message" name="stringBean" value="this is set message"/>

<!--或者 <jsp:setProperty property="message" name="stringBean" value='<%=request.getParameter("message") %>'/>-->
<jsp:getProperty property="message" name="stringBean"/>

</body>
</html>

输出:this is set message

上一篇:vultr vps发布多用户管理功能


下一篇:[Nhibernate]对象状态