Servlet中的一个问题

frankouyang 2003-04-06 12:12:37
package test;
import java.lang.*;
import java.sql.*;
import java.util.*;
import java.io.*;
import javax.servlet.*;

public class ConnectionPool
{
private Vector freeConnections = null;
private Hashtable nowConnections = null;
private String driverName = "";
private String jdbcURL = "";
private int maxConnections = 3;

public ConnectionPool ()
{
}

public void openPool () throws SQLException
{
try
{
nowConnections = new Hashtable (maxConnections);
freeConnections = new Vector (maxConnections);
Class.forName (driverName);
for (int i = 0; i < maxConnections; i ++)
freeConnections.addElement (DriverManager.getConnection (jdbcURL));
}
catch (Exception ex)
{
nowConnections = null;
freeConnections = null;
throw new SQLException (ex.toString ());
}
}

public void closePool () throws SQLException
{
if (nowConnections != null)
{
for (Enumeration e = nowConnections.elements (); e.hasMoreElements (); )
((Connection) e.nextElement ()).close ();
nowConnections.clear ();
nowConnections = null;
}

if (freeConnections != null)
{
for (Enumeration e = freeConnections.elements (); e.hasMoreElements (); )
((Connection) e.nextElement ()).close ();
freeConnections.removeAllElements ();
freeConnections = null;
}
}

public Connection getConnection () throws SQLException
{
if (freeConnections == null)
throw new SQLException ("ConnectionPool还没有建立!");
if (freeConnections.size () == 0)
throw new SQLException ("没有空闲的连接,请稍后再请求!");

Connection conn = (Connection) freeConnections.firstElement ();
freeConnections.removeElement (conn);
nowConnections.put (Thread.currentThread (), conn);

return conn;
}

public void returnConnection () throws SQLException
{
Connection conn = (Connection) nowConnections.remove (Thread.currentThread ());
freeConnections.addElement (conn);
}

public void setPoolSwitch (String on_off) throws ServletException
{
try
{
if (on_off.equalsIgnoreCase ("ON"))
openPool ();
if (on_off.equalsIgnoreCase ("OFF"))
closePool ();
}
catch (SQLException ex)
{
throw new ServletException (ex.toString ());
}
}

public void setMaxConnections (int maxConnections)
{
this.maxConnections = maxConnections;
}

public void setDriverName (String driverName)
{
this.driverName = driverName;
}

public void setJdbcURL (String jdbcURL)
{
this.jdbcURL = jdbcURL;
}
}


"ConnectionPool.java": Error #: 704 : cannot access directory javax\servlet at line 5, column 1
"ConnectionPool.java": Error #: 300 : class ServletException not found in class ConnectionPool at line 76, column 54
"ConnectionPool.java": Error #: 300 : class ServletException not found in class ConnectionPool at line 87, column 14

怎样解决,谢谢
...全文
21 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
frankouyang 2003-04-11
  • 打赏
  • 举报
回复
还是不行
在jdk中编译
ConnectionPool.java:6: package javax.servlet does not exist
import javax.servlet.*;
^
ConnectionPool.java:77: cannot resolve symbol
symbol : class ServletException
location: class test.ConnectionPool
public void setPoolSwitch (String on_off) throws ServletException
^
ConnectionPool.java:88: cannot resolve symbol
symbol : class ServletException
location: class test.ConnectionPool
throw new ServletException (ex.toString ());
^
3 errors

望指点
freeever 2003-04-11
  • 打赏
  • 举报
回复
将servlet.jar加到WEB-INF/lib目录中即可
frankouyang 2003-04-11
  • 打赏
  • 举报
回复
tomcat和jswdk里面都有servlet.jar
惟独resin中没有
可是我现在用resin,不想用其他的怎么办
muskteeeer 2003-04-11
  • 打赏
  • 举报
回复
同意楼上的/
楼上的/楼上的/
楼上的/楼上的/楼上的
caoze 2003-04-11
  • 打赏
  • 举报
回复
你搜索一下你机器里的servlet.jar文件,然后在classpath中添加进去。
frankouyang 2003-04-11
  • 打赏
  • 举报
回复
我在环境变量中设置
G:\jdk\lib\tools.jar;G:\tomcat4.0\bin\;G:\jdk\src.zip;G:\tomcat4.0\classes\

我装了tomcat和resin
现在用的是resin

望高手指点
frankouyang 2003-04-11
  • 打赏
  • 举报
回复
请教:
怎样在classpath中加入servlet.jar
bjzhanghao 2003-04-06
  • 打赏
  • 举报
回复
classpath里没有servlet.jar
zhx_232 2003-04-06
  • 打赏
  • 举报
回复
没有找到你的ConnectonPool这个类,你是不是放的路径不对呢!

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧