1
我有一個類,我試圖從我的jsp頁面檢索變量值,但因爲它是一個單例,它似乎有問題。jsp:useBean with Simple Singleton
MyController.java
public class MyController {
private static volatile MyController myController = new MyController();
private Integer id;
private MyController() {
}
public static MyController MyController() {
return myController;
}
public void display() {
id = 1;
}
}
test.jsp的:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
</head>
<body>
<jsp:useBean id="myController" scope="application" class="test.controller.MyController"/>
<p>
The ID is: ${myController.id}!
</p>
</body>
</html>
錯誤:
org.apache.jasper.JasperException:java.lang中.Clas sNotFoundException: org.apache.jsp.test_jsp
而且,我不知道如何調用從JSP頁面中的display()
方法來初始化id
變量?