jsp可以调用静态方法吗

zcdsunny 2007-10-12 01:27:12
以下是bean:

package wms;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import wms.db.DBTool;

public class DropdownList
{

public static String getUnitList()
{
Statement stms = DBTool.getStatement();
ResultSet rs = null;
String unit_id,unit_name,str_script;

str_script = "";
try
{
rs = stms.executeQuery("select unit_id,unit_name from c_unit_base where type = '3'");
while (rs.next())
{
unit_id = rs.getString("unit_id");
unit_name = rs.getString("unit_name");
str_script += "<OPTION VALUE='"+unit_id.trim()+"'>"+unit_name.trim();
}
} catch (SQLException e)
{
e.printStackTrace();
}
return str_script;
}

public static void main(String arg[])
{
System.out.println("unit:" + getUnitList());
}
}

JSP中是这样调用的:

<jsp:useBean id="wunai" scope="application" class="wms.datalist.DropdownList"/>

以下错误信息:

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 10 in the jsp file: /inorder.jsp

Generated servlet error:
[javac] Compiling 1 source file

F:\jakarta-tomcat-5.0.19\work\Catalina\localhost\kl\org\apache\jsp\inorder_jsp.java:52: ??? wms.datalist ???
wms.datalist.DropdownList wunai = null;
^



An error occurred at line: 10 in the jsp file: /inorder.jsp

Generated servlet error:
F:\jakarta-tomcat-5.0.19\work\Catalina\localhost\kl\org\apache\jsp\inorder_jsp.java:54: ??? wms.datalist ???
wunai = (wms.datalist.DropdownList) _jspx_page_context.getAttribute("wunai", PageContext.APPLICATION_SCOPE);
^



An error occurred at line: 10 in the jsp file: /inorder.jsp

Generated servlet error:
F:\jakarta-tomcat-5.0.19\work\Catalina\localhost\kl\org\apache\jsp\inorder_jsp.java:56: ??? wms.datalist ???
wunai = new wms.datalist.DropdownList();
^



An error occurred at line: 264 in the jsp file: /inorder.jsp

Generated servlet error:
F:\jakarta-tomcat-5.0.19\work\Catalina\localhost\kl\org\apache\jsp\inorder_jsp.java:315: ?????
??? ?? DropdownList
??? ? org.apache.jsp.inorder_jsp
out.print(DropdownList.getUnitList());
^
4 ??


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:553)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.


请各位大虾指教,不胜感激,晚上结贴
...全文
730 13 点赞 打赏 收藏 举报
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
billysky 2007-10-13
你的<%@ page import = "" %> 怎么写的?发上来
  • 打赏
  • 举报
回复
bluedn 2007-10-13



静态方法
package com.bluedn.manager.model.bubean;

import com.bluedn.manager.model.vo.UserPermVO;

public class UserBean extends UserPermVO {

public static void GetPerm(long iPermValue) {

SysManage = (iPermValue & 1) > 0; //系统管理
Bargain = (iPermValue & 2) > 0; //合同管理
BargainAdd = (iPermValue & 4) > 0; //合同登记
BargainUpdate = (iPermValue & 8) > 0; //合同修改
BargainDel = (iPermValue & 16) > 0; //合同删除
BargainQuery = (iPermValue & 32) > 0; //合同查询
BargainExport = (iPermValue & 64) > 0; //合同导出

}

}

<%@ page import="com.bluedn.manager.model.vo.UserPermVO"%>
<%
long iPermValue = Long.parseLong(session.getAttribute("strUserTab").toString());
UserBean.GetPerm(iPermValue);
%>
  • 打赏
  • 举报
回复
caiitly 2007-10-13
导入静态类所在的包试试
  • 打赏
  • 举报
回复
zcdsunny 2007-10-12
但是出错了呀,又不能用import,useBean也不行~郁闷呢
  • 打赏
  • 举报
回复
readykisskis 2007-10-12
当然可以了
  • 打赏
  • 举报
回复
zcdsunny 2007-10-12

<%=DropdownList.getUnitList()%>直接这样调用为何不可以阿?
  • 打赏
  • 举报
回复
neptune0229 2007-10-12
同上,你最前面是package wms;
wms.DropdownList
  • 打赏
  • 举报
回复
for_cyan 2007-10-12
<jsp:useBean id="wunai" scope="application" class="wms.datalist.DropdownList"/ >

确定你这句没错?我感觉是class="wms.DropdownList"
  • 打赏
  • 举报
回复
zcdsunny 2007-10-12

<jsp:useBean id="wunai" scope="application" class="wms.datalist.DropdownList"/ > 去掉之后的错误:

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 263 in the jsp file: /inorder.jsp

Generated servlet error:
[javac] Compiling 1 source file

F:\jakarta-tomcat-5.0.19\work\Catalina\localhost\kl\org\apache\jsp\inorder_jsp.java:306: ?????
??? ?? DropdownList
??? ? org.apache.jsp.inorder_jsp
out.print(DropdownList.getUnitList());
^
1 ??


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)


难道不是静态类型调用问题?弄了几个小时了,大虾们帮帮忙啦,谢谢!!
  • 打赏
  • 举报
回复
zcdsunny 2007-10-12
那为什么还是出错呢,class的文件夹也没放错啊
  • 打赏
  • 举报
回复
ydlchina 2007-10-12
可以
  • 打赏
  • 举报
回复
xiyuan1999 2007-10-12
jsp里面不能调用静态类型的方法吗?


绝对可以
  • 打赏
  • 举报
回复
zcdsunny 2007-10-12
不好意思,bean里面的确是package wms.datalist;还是不行啊

F:\jakarta-tomcat-5.0.19\work\Catalina\localhost\kl\org\apache\jsp\inorder_jsp.java:52: ???? wms.datalist.DropdownList
??????? F:\jakarta-tomcat-5.0.19\webapps\kl\WEB-INF\classes\wms\datalist\DropdownList.class
?????????? 50.0??? 49.0
?????????????????????????
wms.datalist.DropdownList wunai = null;

在jsp里面不能调用静态类型的方法吗?比如直接调用<%=DropdownList.getUnitList()%>
  • 打赏
  • 举报
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2007-10-12 01:27
社区公告
暂无公告