提交 9d35faf1 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 9ce12a7c
......@@ -2,5 +2,5 @@
javac=javac
benchmark.drivers.dir=D\:/data/java
version.name.maven=1.0.20070617
path.servlet.jar=C\:/data/classpath/servlet-api-2.3.jar
path.servlet.jar=C\:/data/classpath/servlet-api.jar
jdk=1.4
......@@ -273,7 +273,7 @@
</target>
<target name="warConsole" depends="compileServlet, jar">
<war destfile="bin/h2console.war" webxml="src/tools/WEB-INF/web.xml">
<war destfile="bin/h2console.war" webxml="src/tools/WEB-INF/web.xml" basedir="src/tools/WEB-INF" includes="console.html">
<lib file="bin/h2.jar" />
</war>
</target>
......
......@@ -37,9 +37,13 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<h3>Version 1.0 (Current)</h3>
<h3>Version 1.0 / TODO (Build TODO)</h3><ul>
<li>Deleting database files didn't work for Windows if the database was on the root directory of a drive.
<li>The H2 Console can now be run as a standalone web application, or it can be embedded as a servlet into any
existing web application. To build the 'H2 Console' web application, execute 'ant warConsole'.
See src/tools/org/h2/server/web and src/tools/WEB-INF for details.
</li><li>Deleting database files didn't work for Windows if the database was on the root directory of a drive.
</li><li>The Polish translation is available. Thanks a lot to Tomek!
</li><li>Windows service: the CLASSPATH was not included when starting the service. Fixed.
</li>
</ul>
<h3>Version 1.0 / 2007-06-17 (Build 50)</h3><ul>
......
......@@ -314,48 +314,15 @@ bad if they don't get closed).
The server mode is similar, but it allows you to run the server in another process.
<h3>Using a Servlet Listener to Start and Stop a Database</h3>
Add the following to the web.xml file (after context-param and before filter):
Add the h2.jar file your web application, and
add the following snippet to your web.xml file (after context-param and before filter):
<pre>
&lt;listener>
&lt;listener-class>db.Starter&lt;/listener-class>
&lt;listener-class>org.h2.server.web.DbStarter&lt;/listener-class>
&lt;/listener>
</pre>
Add the following Starter class:
<pre>
package org.h2.tools.servlet;
import javax.servlet.*;
import java.sql.*;
public class DbStarter implements ServletContextListener {
private Connection conn;
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
Class.forName("org.h2.Driver");
// You can also get the setting from a context-param in web.xml:
// ServletContext servletContext = servletContextEvent.getServletContext();
// String url = servletContext.getInitParameter("db.url");
conn = DriverManager.getConnection("jdbc:h2:test", "sa", "");
} catch (Exception e) {
e.printStackTrace();
}
}
public Connection getConnection() {
return conn;
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
</pre>
For details on how to access the database, see the code DbStarter.java
<br /><a name="csv"></a>
<h2>CSV (Comma Separated Values) Support</h2>
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html>
<head>
<title>H2 Console</title>
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=console/">
</head>
<body>
<a href="console/">H2 Console</a>
</body>
<head>
<title>H2 Console</title>
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=console/" />
</head>
<body>
<a href="console/">H2 Console</a>
</body>
</html>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<web-app 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"
version="2.5">
<display-name>H2 Console Web Application</display-name>
<description>
A web application that includes the H2 Console servlet.
</description>
<servlet>
<servlet-name>H2Console</servlet-name>
<servlet-class>org.h2.server.web.WebServlet</servlet-class>
<init-param>
<param-name>log</param-name>
<param-value>true</param-value>
</init-param>
<display-name>H2 Console Web Application</display-name>
<description>
A web application that includes the H2 Console servlet.
</description>
<servlet>
<servlet-name>H2Console</servlet-name>
<servlet-class>org.h2.server.web.WebServlet</servlet-class>
<init-param>
<param-name>log</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
</servlet>
<servlet-mapping>
<servlet-name>H2Console</servlet-name>
<url-pattern>/console/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/console.html</welcome-file>
</welcome-file-list>
<security-constraint>
<!--
<web-resource-collection>
<web-resource-name>H2 Console</web-resource-name>
<url-pattern>/console/*</url-pattern>
</web-resource-collection>
-->
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
<servlet-mapping>
<servlet-name>H2Console</servlet-name>
<url-pattern>/console/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/console.html</welcome-file>
</welcome-file-list>
<!-- Enable the following section when you want basic authentication -->
<!--
<security-constraint>
<web-resource-collection>
<web-resource-name>H2 Console</web-resource-name>
<url-pattern>/console/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>H2 Console</realm-name>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>H2 Console</realm-name>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
-->
</web-app>
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.server.web;
import javax.servlet.*;
import java.sql.*;
public class DbStarter implements ServletContextListener {
private Connection conn;
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
Class.forName("org.h2.Driver");
org.h2.Driver.load();
// You can also get the setting from a context-param in web.xml:
ServletContext servletContext = servletContextEvent.getServletContext();
// String url = servletContext.getInitParameter("db.url");
......
......@@ -22,71 +22,67 @@ import javax.servlet.http.HttpServletResponse;
import org.h2.util.StringUtils;
public class WebServlet extends HttpServlet {
private static final long serialVersionUID = 9171446624885086692L;
private WebServer server;
private void testLog(String s) {
int todoRefactorSimplify;
int todoRemoveTestLogMethod;
int todoTestWithTomcat;
int todoTestWithJetty;
System.out.println(s);
}
public void init() throws ServletException {
ServletConfig config = getServletConfig();
Enumeration en = config.getInitParameterNames();
ArrayList list = new ArrayList();
while(en.hasMoreElements()) {
String name = (String) en.nextElement();
String value = config.getInitParameter(name);
if(!name.startsWith("-")) {
name = "-" + name;
}
list.add(name);
list.add(value);
}
String[] args = new String[list.size()];
list.toArray(args);
server = new WebServer();
server.setAllowShutdown(false);
try {
server.init(args);
} catch(Exception e) {
throw new ServletException("Init failed", e);
}
}
public void destroy() {
}
private static final long serialVersionUID = 9171446624885086692L;
private WebServer server;
private int todoRefactorRemoveDuplicateCode;
private int todoRemoveSystem_out;
private int todoTestWithTomcat;
private int todoTestWithJetty;
public void init() throws ServletException {
ServletConfig config = getServletConfig();
Enumeration en = config.getInitParameterNames();
ArrayList list = new ArrayList();
while(en.hasMoreElements()) {
String name = (String) en.nextElement();
String value = config.getInitParameter(name);
if(!name.startsWith("-")) {
name = "-" + name;
}
list.add(name);
list.add(value);
}
String[] args = new String[list.size()];
list.toArray(args);
server = new WebServer();
server.setAllowShutdown(false);
try {
server.init(args);
} catch(Exception e) {
throw new ServletException("Init failed", e);
}
}
public void destroy() {
}
boolean allow(HttpServletRequest req) {
if(server.getAllowOthers()) {
return true;
}
String addr = req.getRemoteAddr();
InetAddress address;
try {
address = InetAddress.getByName(addr);
} catch (UnknownHostException e) {
return false;
}
return address.isLoopbackAddress();
String addr = req.getRemoteAddr();
InetAddress address;
try {
address = InetAddress.getByName(addr);
} catch (UnknownHostException e) {
return false;
}
return address.isLoopbackAddress();
}
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String file = req.getPathInfo();
trace("get " + file);
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String file = req.getPathInfo();
if(file == null) {
resp.sendRedirect(req.getRequestURI() + "/");
return;
resp.sendRedirect(req.getRequestURI() + "/");
return;
} else if(file.startsWith("/")) {
file = file.substring(1);
file = file.substring(1);
}
if(file.length() == 0) {
file = "index.do";
}
}
if(!allow(req)) {
file = "notAllowed.jsp";
}
......@@ -94,22 +90,21 @@ public class WebServlet extends HttpServlet {
Properties attributes = new Properties();
Enumeration en = req.getAttributeNames();
while(en.hasMoreElements()) {
String name = (String) en.nextElement();
String value = (String) req.getAttribute(name);
attributes.put(name, value);
String name = (String) en.nextElement();
String value = (String) req.getAttribute(name);
attributes.put(name, value);
}
en = req.getParameterNames();
while(en.hasMoreElements()) {
String name = (String) en.nextElement();
String value = (String) req.getParameter(name);
attributes.put(name, value);
String name = (String) en.nextElement();
String value = req.getParameter(name);
attributes.put(name, value);
}
WebSession session = null;
String sessionId = attributes.getProperty("jsessionid");
if(sessionId != null) {
session = server.getSession(sessionId);
}
int todoSupportCache;
String mimeType;
boolean cache;
int index = file.lastIndexOf('.');
......@@ -129,18 +124,18 @@ public class WebServlet extends HttpServlet {
cache=true;
mimeType = "text/css";
} else if(suffix.equals("html") || suffix.equals("do") || suffix.equals("jsp")) {
cache=false;
cache = false;
mimeType = "text/html";
if (session == null) {
int todoTest;
String hostname = req.getRemoteHost();
int todoTest;
String hostname = req.getRemoteHost();
session = server.createNewSession(hostname);
if (!file.equals("notAllowed.jsp")) {
file = "index.do";
}
}
} else if(suffix.equals("js")) {
cache=true;
cache = true;
mimeType = "text/javascript";
} else {
cache = false;
......@@ -151,36 +146,35 @@ public class WebServlet extends HttpServlet {
server.trace("mimeType="+mimeType);
// parseHeader();
String ifModifiedSince = req.getHeader("if-modified-since");
testLog("@ifmod=" + ifModifiedSince);
server.trace(file);
WebThread app = new WebThread(null, server);
if(file.endsWith(".do")) {
app.setSession(session, attributes);
app.setSession(session, attributes);
file = app.process(file);
}
if(cache && server.getStartDateTime().equals(ifModifiedSince)) {
resp.sendError(HttpServletResponse.SC_NOT_MODIFIED);
bytes = null;
resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
} else {
bytes = server.getFile(file);
bytes = server.getFile(file);
}
if(bytes == null) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
try {
bytes = StringUtils.utf8Encode("File not found: "+file);
} catch(SQLException e) {
int todoNotIgnore;
}
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
try {
bytes = StringUtils.utf8Encode("File not found: "+file);
} catch(SQLException e) {
int todoNotIgnore;
}
} else {
if(session != null && file.endsWith(".jsp")) {
String page = StringUtils.utf8Decode(bytes);
page = PageParser.parse(server, page, session.map);
try {
String page = StringUtils.utf8Decode(bytes);
page = PageParser.parse(server, page, session.map);
try {
bytes = StringUtils.utf8Encode(page);
} catch(SQLException e) {
int todoNotIgnore;
}
} catch(SQLException e) {
int todoNotIgnore;
}
}
resp.setContentType(mimeType);
if(!cache) {
......@@ -194,14 +188,9 @@ public class WebServlet extends HttpServlet {
ServletOutputStream out = resp.getOutputStream();
out.write(bytes);
}
}
private void trace(String s) {
int todo;
System.out.println("## " + s);
}
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
doGet(req, resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
doGet(req, resp);
}
}
......@@ -458,6 +458,7 @@ maxvalue samooha dbrewster minvalue darwin follow graphics typically
netscape mywebpage javaplayer fuse davidlbarron helps player appfuse awt
gridwidth editable pressed entered awt east toolkit insets exited grid mouse west resizable popup focusable bag anchor
headless
polish javaee resp xsi instances tomek realm xsd appended auth polski
### check those again:
populate slowly xacon inser maxbqualsize counter regards attaching official xatest
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论