首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jsp可以调用静态方法吗解决思路

2013-09-11 
jsp可以调用静态方法吗以下是bean:package wmsimport java.sql.ResultSetimport java.sql.SQLException

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.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.


请各位大虾指教,不胜感激,晚上结贴



[解决办法]
<jsp:useBean id="wunai" scope="application" class="wms.datalist.DropdownList"/ >

确定你这句没错?我感觉是class="wms.DropdownList"
[解决办法]
jsp里面不能调用静态类型的方法吗?


绝对可以
[解决办法]
导入静态类所在的包试试
[解决办法]

Java code
静态方法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);%>
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html

热点排行