Basics
sample.jsp
A very simple JSP example which runs some Java code in a JSP page.
Web Apps
AutoRun.java
A servlet designed to be loaded on startup by the servlet container, using <load-on-startup> in web.xml
File I/O
FileServlet.java
A servlet which creates a file in the root servlet folder, writes to it and reads from it.
TCP/IP
TestProxy.java
Complete example of how to retrieve contents of a website through a proxy using URLConnection (with Authentication)
TestProxy2.java
Alternate to TestProxy.java, using a separate Authenticator class, which is more dynamic.
Additional files required:
Encoding/Decoding
Base64.java
Command line java tool to encode or decode Base64 strings.
Customising Tomcat Error Pages
JNDI DBCP (Database Connection Pool)
[App]/META-INF/context.xml
JNDI DataSource Connection Pool setup example for MySQL 5 with the Connector/J JDBC driver
Note that no path= attribute is required in the context tag.
[App]/META-INF/context.xml
JNDI DataSource Connection Pool setup example for MySQL 4 with the Connector/J JDBC driver
Note that no path= attribute is required in the context tag.
[App]/META-INF/context.xml
JNDI DataSource Connection Pool setup example for SQL/Server with the jTDS JDBC driver
Note that no path= attribute is required in the context tag.
[App]/WEB-INF/web.xml
web.xml file for example (minimal, note that no resource-refs are required)
[App]/test.jsp
This example shows how to run a query that uses the connection pool. It uses JSTL tags to run an SQL query using the JNDI data source.
[App]/plain.jsp
Alternate example using JDBC calls directly (no JSTL).
| |
|