0

I'm doing a Webapp that retrieves some information from a database and stores it in a Java bean using the "request" as context , POST method sends the table's information when executed. I'd like to know if it would be better to create the bean as a servletContext to avoid instantiating it every time there is a request from the clients and hopefully reduce the time my application process the requests. I haven't found information regarding using Java beans as ServletContext . Thanks in advance! the original code
using Request:

public class ControleurServlet2 extends HttpServlet {

public void  init() throws   ServletException { 
//Empty   
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//... ... ...    

//Instantiation des Objects  de chaque  Request envoyé par le Client  
ModelEtagere model1=new ModelEtagere();
request.setAttribute("model",model1);//Envoi de Model Bean vers la page JSP 
this.getServletContext().getRequestDispatcher(VUE).forward(request, response);      }

the code using ServletContext:

public class ControleurServlet2 extends HttpServlet {
//Initialisation bean Model1
ModelEtagere model1;

@Override
public void  init() throws   ServletException {
metier= new MagasinMetierImpl();    
model1=new ModelEtagere();
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//ServletContext
ServletContext context=  getServletContext();
//    ...   ...  ...

context.setAttribute("model",model1);//Envoi de Model1 Bean vers la page JSP 
this.getServletContext().getRequestDispatcher(VUE).forward(request, response);      
}

0 Answers0