/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package servlet;
import java.util.List;
import javax.ejb.EJB;
import javax.servlet.*;
import javax.servlet.http.*;
import entityJB.*;
import java.io.IOException;
import java.io.PrintWriter;
/**
*
* @author Administrator
*/
public class Controllerserv extends HttpServlet {
/**
* Processes requests for both HTTP GET
and POST
methods.
* @param request servlet request
* @param response servlet response
*/
@EJB()
private BaleBeanRemote baleBeanRemote;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
List baleent;
out.println("");
out.println("");
out.println("Servlet Controllerserv");
out.println("");
out.println("");
out.println("");
String searchitem=request.getParameter("viewitems");
if(searchitem!= null && searchitem.equals("View All Bales")){
try{
//call the allitems method
baleent=baleBeanRemote.findAllBales();
HttpSession session = request.getSession();
session.setAttribute("baleent",baleent);
RequestDispatcher dispatcher = getServletContext()
.getRequestDispatcher("/Viewdisplay.jsp");
dispatcher.forward(request, response);
//forward data to the Viewdisplay.jsp to present
//it to user
dispatcher.forward(request, response);
}
catch(Exception ex){
System.err.println("Can not show the all bale page");
}
}
else {
try{
//call the allbales method
baleent=baleBeanRemote.findAllBales();
HttpSession session = request.getSession();
session.setAttribute("baleent",baleent);
RequestDispatcher dispatcher = getServletContext()
.getRequestDispatcher("/Viewdisplay.jsp");
dispatcher.forward(request, response);
//forward data to the DiscountItemsj.jsp to present
//it to user
dispatcher.forward(request, response);
}
catch(Exception ex){
System.err.println("Can not show the all BALES page");
}
}
//out.println("Servlet Controllerserv at " + request.getContextPath () + "
");
out.println("");
out.println("");
} finally {
out.close();
}
}
//
/**
* Handles the HTTP GET
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 POST
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";
}
//
}