日期:2014-05-18  浏览次数:20706 次

jsp可以调用静态方法吗
以下是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.