文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>hsqldb随tomcat启动

hsqldb随tomcat启动

时间:2010-04-06  来源:qbq

Servlet:

package com.qbq;

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/");
        server.setDatabaseName(0, "test");
        server.setDatabasePath(0, path);
        server.setPort(8086);
        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>com.qbq.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>


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载