/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.web;

import com.ejb.Notice;
import com.ejb.NoticeFacade;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Administrator
 */
@WebServlet(name = "NoticeList", urlPatterns = {"/NoticeList"})
public class NoticeList extends HttpServlet {

        @EJB
    private NoticeFacade noticeFacade;
    
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
         response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        out.println("<html>");
        out.println("<meta http-equiv='Content-Type' content='text/html'; charset='UTF-8'>");
        out.println("<head>");
        out.println("<title>公告栏</title>");
        out.println("</head>");
        out.println("<body>");
        List notices = noticeFacade.findAll();
        for (Iterator it = notices.iterator(); it.hasNext();) {
            Notice elem = (Notice) it.next();
            out.println(" <b >"+elem.getTitle()+"       <font color='red'>   "+elem.getAuthor()+"</font> </b><br />");
            out.println(elem.getBody()+"<br /> ");
            java.sql.Timestamp pdate=elem.getPublishDate();
            out.println(pdate.toString()+"<br /> ");
           // out.println(elem.getAuthor()+"<br /> ");
        }
        //out.println("<a href='PostNotice'>发布新的公告</a>");
        out.println("</body>");
        out.println("</html>");
        
        out.close();

    }
    
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
   
   
}
