Two Ways of Coding

  1. Using your own computer to code, upload to and run on using its PostgreSQL and Tomcat.
  2. Install your own PostgreSQL and Tomcat and run everything on your own machine.

The Bring-Your-Own-Laptop Way

Attention: Mac users please follow new instructions.

PostgreSQL and Java for Mac Users

I noticed there are a lot of Mac users here. And I just found out that the docker way of doing it doesn’t quite work. What I recommend is doing the followings.

  1. Go and install PostgreSQL directly on your own machine.
  2. Start that application, create all necessary tables according to photoshare/docs/photoshare_schema.sql
  3. Update photoshare/META-INF/context.xml with username being your Mac’s login name and password being empty string.

Java 8 works fine on Mac.

  1. So just execute /usr/libexec/java_home and copy the output path as JAVA_HOME
  2. Also update that path in file

You don’t need any other configuration. Just remember to start Postgres.App application before testing.

For Others

You need your own PostgreSQL, and make sure you have JDK 1.6 installed.

Install JDK 1.6

You can download here. Or if your operating system has a package manager like apt and homebrew, look for openjdk or similar package.

Make sure JAVE_HOME points to the JDK folder after installation. You can google how to set up JAVA_HOME environment variable windows/mac/linux

Install Docker

Follow instructions here Look for your platform.

Start PostgreSQL

docker run --name db -e POSTGRES_PASSWORD=pwd -d -p 5432:5432 postgres

This will give you a running PostgreSQL database on localhost:5432 with username postgres and password pwd. You can then use psql to connect to it.

If you have psql on your system, then

psql -h localhost -U postgres

Otherwise, you can use the psql from the same image you used to start the PostgreSQL server.

docker run -it --rm --link db:postgres postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

There are a lot of cheat sheet for psql, and this is one of them. Just google it.

Check and Modify PA2 Files

Based on your own environment, you need to modify things like JAVA_HOME, PostgreSQL username, password and address, and all related things. Other than these, you can just follow PA2 instructions.

Useful Pages

  • JSP Tutorial:
  • JSP Expression Language Reference Card:
  • JSP Cheat Sheet:
  • Java Cheat Sheet:
  • HttpServlet API Ref:
  • What is “servlet”:
  • What is “ant” in your “ant -f photoshare.xml all”:
  • What is “tomcat” in your “ start”:
  • JavaScript Cheat Sheet:,
  • JavaScript Official Reference Guide:
  • HTML Cheat Sheet:
  • CSS Cheat Sheet:

Three Slides