package com.wxpn.tutorial.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class for Servlet: ReadServlet
 */
public class ReadServlet extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public ReadServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String id = request.getParameter("id");
		String url=request.getParameter("url");
		if (id == null) {
			request.setAttribute("error", "<h1>ÔÄ¶ÁÊ§°Ü!</h1>");
		} else {
			NewsMgr mgr = new NewsMgr();

			News msg = mgr.getMessage(Integer.parseInt(id));
			request.setAttribute("msg", msg);
		}
		try {
			request.getRequestDispatcher(url)
					.forward(request, response);
		} catch (Throwable t) {
			getServletContext().log(t.getMessage());
		}
	}	
}