package festivoServlet;

import java.io.IOException;

import javax.naming.InitialContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;

import m05bBD.m05bFestivo;
import m05bClasses.m05bFileLog;
import m05bFestivoEJB.m05Festivo;
import m05bFestivoEJB.m05FestivoHome;
import m05bFestivoEJB.m05FestivoPK;
/**
 * Inserte aquí la descripción del tipo.
 * Fecha de creación: (30/11/05)
 */
public class m05bGenerarFestivoServlet extends javax.servlet.http.HttpServlet {m05bFileLog miLog = new m05bFileLog();
/**
 * Process incoming HTTP GET requests 
 * 
 * @param request Object that encapsulates the request to the servlet 
 * @param response Object that encapsulates the response from the servlet
 */
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

	performTask(request, response);

}
/**
 * Returns the servlet info string.
 */
public String getServletInfo() {

	return super.getServletInfo();

}
/**
 * Initializes the servlet.
 */
public void init() {
	// insert code to initialize the servlet here

}
/**
 * Process incoming requests for information
 * 
 * @param request Object that encapsulates the request to the servlet 
 * @param response Object that encapsulates the response from the servlet
 */
public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {

	try

	{
		// Insert user code from here.

		String codigo, fecha, descripcion;
		String sURL = "";
		String msg;
		HttpSession session = request.getSession(true);

		codigo = new String(request.getParameter("Codigo"));

		try{
			m05FestivoPK primaryKey = new m05FestivoPK();
			primaryKey.fes_codigo = codigo;
			InitialContext ctx2 = new InitialContext();
			m05FestivoHome festivoEBHome = (m05FestivoHome) ctx2.lookup("m05Festivo");
			m05Festivo festivoEB = festivoEBHome.findByPrimaryKey(primaryKey);
			m05bFestivo festivo = festivoEB.getFestivo();
			session.setAttribute("m05bFestivo", festivo);
	    	sURL = response.encodeRedirectURL("m05bFestivosJsp.jsp?Codigo=" + codigo + "&Mensaje=false");

		    RequestDispatcher rd;
		    rd = request.getRequestDispatcher(sURL);
	        
		    try{
		      rd.forward(request, response);
	    	} 
		    catch (ServletException e){
		    	response.sendRedirect("m05bError.jsp");
		    }    	
		} catch (Exception SQLException) {
			response.sendRedirect("m05bError.jsp");
		}

	}
	catch(Throwable theException)
	{
		try {
			// uncomment the following line when unexpected exceptions
			// are occuring to aid in debugging the problem.
			//miLog.addTraza(theException);
			response.sendRedirect("m05bError.jsp");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			miLog.addTraza(e);
		}
	}
}
}