Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30479093
  • 博文数量: 708
  • 博客积分: 12163
  • 博客等级: 上将
  • 技术积分: 8240
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-04 20:59
文章分类

全部博文(708)

分类: Java

2010-04-06 09:35:07

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+
"/test");//test为数据库名
        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=""
    xmlns:xsi=""
    xsi:schemaLocation=" /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>


阅读(2355) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~