import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import javax.servlet.ServletConfig;
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.servlet.VelocityServlet;

public class HelloServlet extends VelocityServlet {

	protected Properties loadConfiguration(ServletConfig config)
		throws IOException, FileNotFoundException {

		Properties prop = new Properties();
		String path = config.getServletContext().getRealPath("/");
		prop.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
		//prop.setProperty("runtime.log", path + "velocity.log");
		prop.setProperty("default.contentType", "text/html; charset=Shift_JIS");
		prop.setProperty("input.encoding", "Shift_JIS");
		prop.setProperty("output.encoding", "Shift_JIS");
		return prop;

	}

	public Template handleRequest(
		HttpServletRequest request,
		HttpServletResponse response,
		Context ctx) {

		ctx.put("title", "どう思う？");

		List list = new ArrayList();
		list.add("Velocityってすげえ！");
		list.add("Velocityって最高！");
		list.add("ELでいいんじゃないの？");
		ctx.put("items", list);

		try {
			Template template = getTemplate("hellohtml.vm");
			return template;
		} catch (Exception e) {
			throw new IllegalStateException(e.toString());
		}
	}
}
