[Java Web] JavaBean

來源:互聯網
上載者:User

標籤:type   建立   isp   htm   方法   value   sed   code   jsp   

一、編碼規則

  1. 每個屬性都有對應的set方法和get方法。
  2. 若屬性為布爾類型,則對應set方法和is方法。
  3. 所有的屬性均為私人,所有的方法均為公有。
  4. 類中必須有無參建構函式。

 

二、使用

<jsp:useBean>用於建立JavaBean執行個體。

<jsp:setProperty>和<jsp:getProperty>對應set方法和get方法。

<%@ page contentType="text/html;charset=UTF-8" language="java" %><!DOCTYPE html><html><body><!-- 使用預設包會拋出ClassNotFoundException --><jsp:useBean id="stu" class="bean.Student" scope="page"/><jsp:setProperty name="stu" property="number" value="30"/><jsp:setProperty name="stu" property="name" value="Yao"/><jsp:setProperty name="stu" property="gender" value="male"/><jsp:getProperty name="stu" property="number"/><jsp:getProperty name="stu" property="name"/><jsp:getProperty name="stu" property="gender"/></body></html>
View Code

 

三、範圍

  • page:只能在建立的頁面中訪問。
  • request:在用戶端的一次請求中有效。
  • session:在用戶端與服務端建立串連直到串連中斷期間有效。
  • application:在服務端關閉之前都一直保持有效。

[Java Web] JavaBean

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.