浏览 218 次
|
锁定老贴子 主题:JSP调用Bean的问题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
最后更新时间:2007-08-17
我是个Java新手,想试试Hibernate,不过测试它光初始化就要1秒多,貌似不用application生存范围的Bean包装是不行的吧
JSP代码如下: index.jsp
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<jsp:useBean id="cnt" scope="application" class="counter.Counter" />
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>
<!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>JSP Page</title>
</head>
<body>
<h1>JSP Page</h1>
<br/>
<a href="./Welcome.do">Struts 欢迎页<br/>您是第 <%=cnt.getCount()%></a>
<%--
This example uses JSTL, uncomment the taglib directive above.
To test, display the page like this: index.jsp?sayHello=true&name=Murphy
--%>
<%--
<c:if test="${param.sayHello}">
<!-- Let's welcome the user ${param.name} -->
Hello ${param.name}!
</c:if>
--%>
</body>
</html>
对应的Bean(一个测试的,类似计数器样的) Counter.java
package counter;
/**
*
* @author wps2000
*/
public class Counter {
private int count;
/** Creates a new instance of Counter */
private Counter() {
count = 0;
}
public void setCount(int count)
{
this.count = count;
}
public int getCount()
{
count++;
return count;
}
}
我已经把 Counter.java 编译成 class了放到 WEB-INF/CLASSES/counter 下面了,但是执行index.jsp出现问题: 引用 org.apache.jasper.JasperException: The value for the useBean class attribute counter.Counter is invalid. 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |


