| $CATALINA_HOME | -------- | webapps | -------- | zenobia | -------- | WEB-INF | ----+---- | build.xml | ||||
| | | ||||||||||||
| +---- | build.properties | |||||||||||
| | | ||||||||||||
| +---- | web.xml | |||||||||||
| | | ||||||||||||
| +---- | src | -------- | Zxxhello | -------- | HelloWorld.java | |||||||
| | | ||||||||||||
| +---- | classes | |||||||||||
<?xml version="1.0"?>
<project name="zenobia" default="compile" basedir=".">
<property file="build.properties"/>
<target name="clean">
<echo>Clean - classes dir</echo>
<delete dir="${destdir}" />
</target>
<target name="prepare">
<mkdir dir="${destdir}" />
</target>
<target name="compile"
depends="prepare, Zxxhello.compile"/>
<path id="zenobia-classpath">
<pathelement location="${servlet.jar}" />
<pathelement path="${my.classpath}" />
</path>
<target name="Zxxhello.compile">
<javac srcdir="${srcdir}"
includes="${Zxxhello.includes}"
destdir="${destdir}"
deprecation="${compile.deprecation}"
debug="${compile.debug}"
optimize="${compile.optimize}" >
<classpath refid="zenobia-classpath" />
</javac>
</target>
</project>
|
# ----- CATALINA_HOME -----
catalina.home=/usr/local/src/jakarta-tomcat-4.1.18
# ----- Servlet 2.3 -----
servlet.jar=${catalina.home}/common/lib/servlet.jar
# ------ classpath for mine -----
webapp.base=${catalina.home}/webapps/zenobia
my.classpath=${webapp.base}/WEB-INF/classes
# ---- compile options ----
compile.debug=on
compile.deprecation=on
compile.optimize=on
srcdir=${webapp.base}/WEB-INF/src
destdir=${my.classpath}
Zxxhello.includes=Zxxhello/*.java
# compile.encoding=Shift_JIS
# resource.encoding=Shift_JIS
resource.srcdir=${srcdir}
resource.destdir=${destdir}
shared.lib=${catalina.home}/shared/lib
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Welcome to zenobia</display-name>
<description>
Welcome to zenobia
</description>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>Zxxhello.HelloWorld</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>Hello World !</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello.html</url-pattern>
</servlet-mapping>
</web-app>
|
package Zxxhello;
import java.io.PrintWriter;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorld extends HttpServlet {
private String message = null;
public void init() throws ServletException {
message = getInitParameter("message");
log("init(): This message is "+message);
}
public void destroy() {
log("destroy(): See you later !");
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException {
log("doGet(): "+message+" is on the browser");
response.setContentType("text/html; charset=utf-8");
PrintWriter writer = response.getWriter();
writer.println(getMessage());
}
private String getMessage() {
StringBuffer sb = new StringBuffer();
sb.append("<html><head><title>");
sb.append(message);
sb.append("</title></head><body>");
sb.append(message);
sb.append("</body></html>");
return new String(sb);
}
}
|
| $CATALINA_HOME | -------- | webapps | -------- | zenobia | ----+---- | WEB-INF | ----+---- | build.xml | ||||
| | | | | |||||||||||
| | | +---- | build.properties | ||||||||||
| | | | | |||||||||||
| | | +---- | web.xml | ||||||||||
| | | | | |||||||||||
| | | +---- | template | -------- | velhello.vm | ||||||||
| | | | | |||||||||||
| | | +---- | conf | -------- | velocity.properties | ||||||||
| | | | | |||||||||||
| | | +---- | src | -------- | Zxxhello | ----+---- | HelloWorld.java | ||||||
| | | | | | | ||||||||||
| | | | | +---- | VelHello.java | |||||||||
| | | | | |||||||||||
| | | +---- | classes | ||||||||||
| | | ||||||||||||
| +---- | css | -------- | style.css | |||||||||
<HTML>
<HEAD>
<TITLE>$message</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=EUC_JP">
<LINK HREF="css/style.css" type="text/css" REL="stylesheet">
</HEAD>
<BODY>
<TABLE BORDER="2" CLASS="default">
<TR><TD CLASS="body">$message</TD></TR>
</TABLE>
</BODY>
</HTML>
|
runtime.log=WEB-INF/logs/velocity.log runtime.log.error.stacktrace=true # input.encoding=Shift_JIS output.encoding=UTF-8 default.contentType=text/html; charset=utf-8 file.resource.loader.path=WEB-INF/template hello.template.name=velhello.vm |
body {
margin: 50;
font-family: "helvetica", "verdana", "tahoma", "arial", sans-serif;
font-size: 13pt;
}
td.body {
background-color: #525D76;
border-style: none;
font-weight: bold;
font-size: bigger;
color: #ffffff;
padding: 8px;
text-align: justify;
}
|
<?xml version="1.0"?>
<project name="zenobia" default="compile" basedir=".">
<property file="build.properties"/>
<target name="clean">
<echo>Clean - classes dir</echo>
<delete dir="${destdir}" />
</target>
<target name="prepare">
<mkdir dir="${destdir}" />
</target>
<target name="compile"
depends="prepare, Zxxhello.compile"/>
<path id="zenobia-classpath">
<pathelement location="${servlet.jar}" />
<pathelement path="${my.classpath}" />
<pathelement location="${velocity.jar}" />
</path>
<target name="Zxxhello.compile">
<javac srcdir="${srcdir}"
includes="${Zxxhello.includes}"
destdir="${destdir}"
deprecation="${compile.deprecation}"
debug="${compile.debug}"
optimize="${compile.optimize}" >
<classpath refid="zenobia-classpath" />
</javac>
</target>
</project>
|
# ----- CATALINA_HOME -----
catalina.home=/usr/local/src/jakarta-tomcat-4.1.18
# ----- Servlet 2.3 -----
servlet.jar=${catalina.home}/common/lib/servlet.jar
# ----- Velocity 1.3.1 rc2 -----
velocity.jar=${catalina.home}/shared/lib/velocity-dep-1.3.1-rc2.jar
# ------ classpath for mine -----
webapp.base=${catalina.home}/webapps/zenobia
my.classpath=${webapp.base}/WEB-INF/classes
# ---- compile options ----
compile.debug=on
compile.deprecation=on
compile.optimize=on
srcdir=${webapp.base}/WEB-INF/src
destdir=${my.classpath}
Zxxhello.includes=Zxxhello/*.java
# compile.encoding=Shift_JIS
# resource.encoding=Shift_JIS
resource.srcdir=${srcdir}
resource.destdir=${destdir}
shared.lib=${catalina.home}/shared/lib
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Welcome to zenobia</display-name>
<description>
Welcome to zenobia
</description>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>Zxxhello.HelloWorld</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>Hello World !</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>velhello</servlet-name>
<servlet-class>Zxxhello.VelHello</servlet-class>
<init-param>
<param-name>properties</param-name>
<param-value>/WEB-INF/conf/velocity.properties</param-value>
</init-param>
<init-param>
<param-name>message</param-name>
<param-value>Hello World !</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>velhello</servlet-name>
<url-pattern>/velhello.html</url-pattern>
</servlet-mapping>
</web-app>
|
package Zxxhello;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
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.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.context.Context;
import org.apache.velocity.runtime.RuntimeSingleton;
import org.apache.velocity.servlet.VelocityServlet;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import Zxxhello.Util;
public class VelHello extends VelocityServlet {
protected Properties properties = null;
private String message = null;
private String templateName = null;
protected Properties loadConfiguration(ServletConfig config)
throws IOException,
FileNotFoundException {
String propsFile =
Util.getRealPath(getServletContext(),
config.getInitParameter(INIT_PROPS_KEY));
properties = new Properties();
properties.load(new FileInputStream(propsFile));
String log =
Util.getRealPath(getServletContext(),
properties, Velocity.RUNTIME_LOG);
if (log != null) {
properties.setProperty(Velocity.RUNTIME_LOG, log);
}
String path =
Util.getRealPath(getServletContext(),
properties,
Velocity.FILE_RESOURCE_LOADER_PATH);
if (path != null) {
properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,
path);
}
return properties;
}
public void init(ServletConfig config)
throws ServletException {
super.init(config);
message = getInitParameter("message");
RuntimeSingleton.info("init(): This message is "+message);
templateName = properties.getProperty("hello.template.name");
}
public void destroy() {
RuntimeSingleton.info("destroy(): See you later !");
}
public Template handleRequest(HttpServletRequest request,
HttpServletResponse response,
Context context)
throws Exception {
RuntimeSingleton.debug("doGet(): "+message+" is on the browser");
context.put("message", message);
Template template = null;
try {
template = getTemplate(templateName);
} catch (ParseErrorException e) {
RuntimeSingleton.error(e.getMessage());
} catch (ResourceNotFoundException e) {
RuntimeSingleton.error(e.getMessage());
} catch (Exception e) {
RuntimeSingleton.error(e.getMessage());
} finally {
return template;
}
}
}
|
| $CATALINA_HOME | ----+---- | webapps | -------- | zenobia | ----+---- | WEB-INF | ----+---- | build.xml | ||||
| | | | | | | ||||||||||
| | | | | +---- | build.properties | |||||||||
| | | | | | | ||||||||||
| | | | | +---- | web.xml | |||||||||
| | | | | | | ||||||||||
| | | | | +---- | template | -------- | velhello.vm | |||||||
| | | | | | | ||||||||||
| | | | | +---- | conf | -------- | velocity.properties | |||||||
| | | | | | | ||||||||||
| | | | | +---- | src | -------- | Zxxhello | ----+---- | HelloWorld.java | |||||
| | | | | | | | | |||||||||
| | | | | | | +---- | VelHello.java | ||||||||
| | | | | | | | | |||||||||
| | | | | | | +---- | HelloZxx.java | ||||||||
| | | | | | | ||||||||||
| | | | | +---- | classes | |||||||||
| | | | | |||||||||||
| | | +---- | css | -------- | style.css | ||||||||
| | | ||||||||||||
| +---- | server.xml | |||||||||||
<!-- 2 line add by Mie Suemitsu 03/18/2003 -->
<Context path="/fukuju-develop" docBase="fukuju-develop" debug="0"
reloadable="true" crossContext="true">
<!-- 43 line add by Mie Suemitsu 03/29/2003 -->
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_colorful_log." suffix=".txt"
timestamp="true" />
<Resource name="jdbc/hellodb"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/hellodb">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>hoge</value>
</parameter>
<parameter>
<name>password</name>
<value>hogehoge</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.postgresql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:postgresql://localhost:5432/hellodb</value>
</parameter>
</ResourceParams>
</Context>
|
package P16Master;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.StringWriter;
import java.io.IOException;
import java.util.Properties;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
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.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.context.Context;
import org.apache.velocity.runtime.RuntimeSingleton;
import org.apache.velocity.servlet.VelocityServlet;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.MethodInvocationException;
import P16Master.Util;
public class HelloZxx extends VelocityServlet {
Connection db = null;
Statement st = null;
ResultSet rs = null;
private String sqlString = "select * from music where id = 5;";
private String jndiName = "java:comp/env/jdbc/hellodb";
private DataSource dataSource = null;
protected Properties properties = null;
private String templateName = null;
private String message = "Hello Zxx";
private String message2 = "Hello DataSource なのだ";
private String message3 = null;
private String message4 = "Cannot access";
protected Properties loadConfiguration(ServletConfig config)
throws IOException, FileNotFoundException
{
String propsFile
= Util.getRealPath(getServletContext(),
config.getInitParameter(INIT_PROPS_KEY));
properties = new Properties();
properties.load(new FileInputStream(propsFile));
String log
= Util.getRealPath(getServletContext(),
properties, Velocity.RUNTIME_LOG);
if (log != null)
{
properties.setProperty(Velocity.RUNTIME_LOG, log);
}
String path
= Util.getRealPath(getServletContext(),
properties, Velocity.FILE_RESOURCE_LOADER_PATH);
if (path != null)
{
properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
}
return properties;
}
public void init( ServletConfig config) throws ServletException
{
super.init(config);
message3 = getInitParameter("message3");
templateName = properties.getProperty("hellozxx.template.name");
try
{
javax.naming.Context ctx = new InitialContext();
dataSource = (DataSource)ctx.lookup(jndiName);
db = dataSource.getConnection();
st = db.createStatement();
}
catch (NamingException e)
{
throw new ServletException(e.getMessage(), e);
}
catch (NullPointerException e)
{
throw new ServletException("Context is null.");
}
catch (SQLException e)
{
throw new ServletException(e.getMessage(), e);
}
}
public Template handleRequest(HttpServletRequest request,
HttpServletResponse response,
Context context)
{
try
{
rs = st.executeQuery(sqlString);
if(rs != null)
{
while(rs.next())
{
message4 = rs.getString("title");
}
}
else
{
}
rs.close();
st.close();
db.close();
}
catch(Exception e)
{
}
context.put("message", message);
context.put("message2", message2);
context.put("message3", message3);
context.put("message4", message4);
Template template = null;
try
{
template = getTemplate(templateName);
}
catch(ResourceNotFoundException e)
{
// could not found the template
}
catch(ParseErrorException e)
{
// Sintax Error
}
catch(Exception e)
{
}
return template;
}
}
|