日期:2014-05-17  浏览次数:20746 次

javabean怎么用啊,我这段代码哪里错了
<%@ page language="java" contentType="text/html; charset=utf-8"  %>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSPstarting page</title>
</head>
  <body>
    <%request.setCharacterEncoding("utf-8");%>
  <jsp:useBean class="org.xml.person.one" id="one" scope="page" beanName="one"></jsp:useBean>
  <jsp:setProperty name="one" property="*" />
  <jsp:getProperty name="one" property="name"/>
  <jsp:getProperty name="one" property="age"/>
  </body>
</html>

------解决方案--------------------
Clsss

public class Person {

String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

jsp:

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean class="com.apobates.test.Person" id="person" scope="page">
</jsp:useBean>
<jsp:setProperty property="name" name="person" value="xiaofanku" />
Name:<jsp:getProperty property="name" name="person" />
</body>
</html>

------解决方案--------------------
一楼正解