hsqldb随tomcat启动

xiaoxiao2025-12-04  4

Servlet: package demo.web;import java.io.IOException;import javax.servlet.ServletConfig;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.hsqldb.Server;public class PathServlet extends HttpServlet { private Server server = new Server(); public void destroy() { server.shutdown(); super.destroy(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } public void init(ServletConfig config) throws ServletException { String args[] = new String[0]; String path=config.getServletContext().getRealPath("/WEB-INF/lib/db/"); server.setDatabaseName(0, "hsqlDemo"); server.setDatabasePath(0, path); server.setPort(9001); server.setSilent(true); Thread thread=new Thread(new Runnable(){ public void run() { server.start(); } }); thread.start(); }} web.xml <?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>PathServlet</servlet-name> <servlet-class>demo.web.PathServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>PathServlet</servlet-name> <url-pattern>/PathServlet</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app> 相关资源:敏捷开发V1.0.pptx
转载请注明原文地址: https://www.6miu.com/read-5040328.html

最新回复(0)