/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import Bean.LetterDetails;


public class LetterProcess extends HttpServlet {
  
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String serial=request.getParameter("serial");
            String letterno=request.getParameter("letterno");
            String letterdate=request.getParameter("letterdate");
            String receivedfrom= request.getParameter("receivedfrom");
            String subject=request.getParameter("subject");
            String markedto=request.getParameter("markedto");
            String action=request.getParameter("action");
            String demiofficial=request.getParameter("demiofficial");
            String lettername=request.getParameter("lettername");
            String lettertype=request.getParameter("lettertype");
          String sendto=request.getParameter("sendto");
			String entrydate=request.getParameter("entrydate");
            String entrytime=request.getParameter("entrytime");
           LetterDetails ild = new LetterDetails();    
            DataBase dbc= new DataBase();
                
							ild.setSerial(serial);
							ild.setLetterno(letterno);
							ild.setLetterdate(letterdate);
							ild.setReceivedfrom(receivedfrom);
							ild.setSubject(subject);
							ild.setMarkedto(markedto);
							ild.setAction(action);
						    ild.setSendto(sendto);
							ild.setDemiofficial(demiofficial);
							ild.setLettername(lettername);
							ild.setLettertype(lettertype);
							ild.setEntrydate(entrydate);
							ild.setEntrytime(entrytime);
							int i= dbc.letterEntry(ild) ;
						 
			if(i>0)
		{
              request.setAttribute("insert","InsertedSuccessfully");
               RequestDispatcher rd = request.getRequestDispatcher("letter.jsp");
               rd.forward(request, response);
		}
else
		{
				    request.setAttribute("error","Not Submitted");
                   RequestDispatcher rd=request.getRequestDispatcher("letter.jsp");
                rd.forward(request, response);
		}
   
		
	}		
		catch(Exception e){
		
out.println(e);

		}
          
          finally { 
            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";
    }
    // </editor-fold>
}
