初学jsp,遇到jsp中引用javabean的问题
TestBean.java
public class TestBean {
private String string1=null;
private String string2=null;
public void setString1(String value){
string1=value;
}
public void setString2(String value){
string2=value;
}
public String getString1(){
return string1;
}
public String getString2(){
return string2;
}
}
<%@ 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 'MyJsp.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>
HELLO,world!. <br>
<jsp:useBean id="test" class="TestBean"/>
<%
test.setString1("Hello");
test.setString2("woeld");
%>
<%
test.getString1();
%>
<br>
<%
test.getString2();
%>
</body>
</html>
name对象名称,对应的bean的属性
value所赋的值;
然后再<jsp:getProperty 来获取属性的值;