猿问

jsp类的静态属性如何显示到网页中 ?

1.直接上类代码:
import javax.servlet.http.*;
public class listenTest implements HttpSessionListener{
public static int count; --此处定义了静态变量
public listenTest() {
super();
// TODO Auto-generated cons;tructor stub
count=0;
}....

2.在网页中引用的格式:
<%=listenTest.count %> 

3.在运行网页进行测试时的错误:
An error occurred at line: 113 in the jsp file: /index.jsp
listenTest cannot be resolved to a variable
110: 
111: <%/**涓嬮溃涓鸿〃鍗曞强鍙傛暟銆佽烦杞祴璇�/ %>
112: <% out.print("--------------------------琛ㄥ崟娴嬭瘯 -----------------------------------------"); %>
113: <%=listenTest.count %> 
114: 
115: 
116: <form name="form1" action="x.ao" method="post"><br>

慕的地6264312
浏览 575回答 2
2回答

繁花不似锦

要实现JSP静态属性在网页中显示,应考虑对象和静态函数两种情况,具体如下:1、对象。参照jsp:bean的用法,配合使用jsp:getProperty即可。2、静态的函数。在<%@ page language="java" import="java.util.*,com.rh.entity.*" contentType="text/html; charset=GB18030"pageEncoding="GB18030"%>import="java.util.*,com.rh.entity.*" 加上这句,保证Infomation 类的全路径,即可在jsp中使用<%=Infomation.getJavaRuntimeVersion() %>综上,JSP静态属性即可显示在网页中.
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答