|
[li]package Servlet;[/li][li]
[/li][li]ervlet;
[/li][li][/li][li]import java.io.IOException;[/li][li]import java.io.PrintWriter;[/li][li]import java.sql.Connection;[/li][li]import java.sql.DriverManager;[/li][li]import java.sql.ResultSet;[/li][li]import java.sql.SQLException;[/li][li]import java.sql.Statement;[/li][li][/li][li]import javax.servlet.ServletContext;[/li][li]import javax.servlet.ServletException;[/li][li]import javax.servlet.http.HttpServlet;[/li][li]import javax.servlet.http.HttpServletRequest;[/li][li]import javax.servlet.http.HttpServletResponse;[/li][li][/li][li]public class ListServlet extends HttpServlet[/li][li]{[/li][li] private String url;[/li][li] private String user;[/li][li] private String password;[/li][li][/li][li] public void init() throws ServletException[/li][li] {[/li][li] ServletContext sc=getServletContext();[/li][li] String driverClass=sc.getInitParameter("driverClass");[/li][li] url=sc.getInitParameter("url");[/li][li] user=sc.getInitParameter("user");[/li][li] password=sc.getInitParameter("password");[/li][li] try[/li][li] {[/li][li] Class.forName(driverClass);[/li][li][/li][li] }[/li][li] catch(ClassNotFoundException ce)[/li][li] {[/li][li] throw new ServletException("加载数据库驱动失败!");[/li][li] }[/li][li] }[/li] |
|