给一个完整又简单的javaBean例子,我总是使用不了javaBean,错误是无效的javaBean
给一个完整又简单的javaBean例子,我总是使用不了javaBean,错误是无效的javaBean
[解决办法]
就是一个class实现序列化后对类里面所有的字段进行getter and setter方法就可以了
[解决办法]
你路径不对
[解决办法]
public Class TestJavaBean
{
private String field1;
public setField1(String field1)
{
this.field1=field1;
}
public getField1()
{
return field1;
}
}
[解决办法]
提供一个完整的javabean例子.
在Tomcat下部署把这个应用放在webapps目录下,目录结构是这样的:
webapps\counterapp\Counter.jsp
webapps\counterapp\src\mypack\CounterBean.java
webapps\counterapp\WEB-INF\classes\web.xml
webapps\counterapp\WEB-INF\classes\mypack\CounterBean.class
源代码如下:
-------------------Counter.jsp----------------------
<%@ page import= "mypack.CounterBean " %>
<html>
<head> <title> CounterApp </title> </head>
<jsp:useBean id= "myBean " scope= "session " class= "mypack.CounterBean " />
<body>
Current count value is:
<jsp:getProperty name= "myBean " property= "count "/>
<jsp:setProperty name= "myBean " property= "count " value= " <%= myBean.getCount()+1 %> " />
</body>
</html>
---------------------CounterBean.java---------------------
package mypack;
public class CounterBean {
private int count=0;
public CounterBean() {}
public int getCount(){
return count;
}
public void setCount(int count){
this.count=count;
}
}
--------------------web.xml------------------
<?xml version= "1.0 " encoding= "ISO-8859-1 " ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN " "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd ">
<web-app> </web-app>
编译CounterBean.java后的class文件放到上面指定的目录.启动tomcat.
使用http://localhost:8080/counterapp/Counter.jsp访问这个Web应用,
初始页面显示是Current count value is: 0
然后每点一次刷新按钮,显示的值增加1.
[解决办法]
没有遵守javabean的规范