<jsp:useBean>怎麼用
- 2022-09-15
package com。jsp。bean;
public class TestBean {
private String userName;
private String password;
private int age;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this。userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this。password = password;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this。age = age;
}
}
<%@ page language=“java” pageEncoding=“gb2312”%>
或者用以下,param可以不填寫,其中param對應的是提交頁面的表單name
註冊成功:
使用Bean的屬性方法
使用者名稱: <%=user。getUserName()%>
密碼: <%=user。getPassword()%>
年齡: <%=user。getAge()%>
使用getProperty
使用者名稱:
密碼:
年齡:
客戶端名稱:<%=request。getRemoteAddr() %>
一:
二:
1,property=“*”
2,property=“propertyName” param=“parameterName”
3,property=“propertyName”
4,property=“propertyName” value=“property value”
三:
<%
string a=nod1。nod32();
%>
在標籤中定義的id其實就是bean的一個物件,相當於“nod nod1=new nod();”,之後就可以透過這個id呼叫bean中的方法了。 不一定在body標籤中,頁面中任意位置都可以,不過一般不會在最後面啦。
<%
String a=nod1。nod32();
%>
在
樓主的jsp裡對應寫法
請注意標點符號英文狀態下輸入
1 建議樓主去複習下javabean的基礎知識
getter setter方法 以及相關的屬性宣告是javabean的基本結構。
2。
三個基本屬性 id ——唯一標識 scope——bean的 屬性範圍(總共有四種屬性範圍:page、session、request、application) class——引用bean所在的相對路徑