你把struts 的所有包都放进去 .
我上次也是这样的.
我上次也是这样的.
解决方案 »
- 十万火急!POI不能准确读取excel批注 求高人帮助!
- jdom 如何查询带 命名空间的xml 又如何修改呢
- ireport怎样设置背景图片啊?????????
- HTTP Status 500 - zhanghao is not mapped [from zhanghao where ygh=? and mm=?]
- struts2 没有默认加载的配置文件!
- 请各位帮忙看一下拉
- 关于Axis自动生成wsdl的问题
- OpenSessionInView如何使用?
- struts+spring+hibernate的问题,请高手指点。急急。。。。。。。。。。。。
- CMP和Blob的问题,能用CMP实现对具有Blob字段的数据库的调用么?
- 郁闷,Weblogic 8.1 sp1数据库连接问题
- 在JBoss中测试stateful session bean的activation和passivation问题!
所以的常建议采用《JSP Web编程指南》中的方法,自己建立数据库连接类:
ConnectionPool.java:
package OST.jdbc.util;import java.sql.SQLException;
import java.sql.Connection;
import javax.sql.DataSource;public class ConnectionPool { private DataSource ds; private static ConnectionPool mySelf;
private ConnectionPool(DataSource ds) {
this.ds = ds;
}
public static void init(DataSource ds) {
mySelf = new ConnectionPool(ds);
} public static ConnectionPool getInstance() { if (mySelf == null) {
throw new IllegalStateException("Pool not initialized.");
}
return mySelf; } public Connection getConnection() throws SQLException {
return ds.getConnection();
}}
--------------------------------------------------------------
DBInitServlet.java:
package OST.jdbc.util;import javax.servlet.http.HttpServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;import java.sql.SQLException;
import java.sql.Connection;
import javax.sql.DataSource;import org.apache.struts.util.GenericDataSource;public class DBInitServlet extends HttpServlet { public void init(ServletConfig config) throws ServletException { super.init(config); try { GenericDataSource ds = new GenericDataSource(); ds.setDriverClass(getInitParameter("driverClass"));
ds.setUrl(getInitParameter("jdbcURL"));
ds.setMinCount(Integer.parseInt(getInitParameter("minCount")));
ds.setMaxCount(Integer.parseInt(getInitParameter("maxCount")));
ds.setAutoCommit(false); ds.setUser(getInitParameter("user"));
ds.setPassword(getInitParameter("password"));
ds.open(); ConnectionPool.init(ds); } catch (SQLException e) {
e.printStackTrace();
throw new ServletException("Unable to open datasource.");
}
}
}
------------
这样就可以在其它类中使用它。
例如:
Connection con = null; try
{
con = pool.getConnection();
lykDAO m_lykDAO = new lykDAO(con); String action=request.getParameter("action");
if(action==null)action="find";
if(action.equals("delete"))
{
String expression=request.getParameter("expression");
m_lykDAO.removeID(expression);
}
////////////
if(action.equals("update"))
{
String expression=request.getParameter("expression");
lyk m_lyk= new lyk();
//<update>
m_lyk.setUser_id(m_lykForm.getUser_id());
m_lyk.setPassword(m_lykForm.getPassword());
m_lyk.setName(m_lykForm.getName());
m_lyk.setDescription(m_lykForm.getDescription());
m_lyk.setWeb_site(m_lykForm.getWeb_site());
m_lyk.setAddress(m_lykForm.getAddress());
//</update>
m_lykDAO.update(m_lyk,expression);
}
}