Passing of Parameters between a jsp and two servlets?

0

I have a doubt maybe a little difficult to be clarified!

I'm using a programming methodology called MVC, as everyone knows, and in this situation (Java EE) in the controller is the handler (servlts) in the model are the classes and the view that in this case and the JSP ' s.

And my doubt is this: It has a form in a jps in which, what I want to happen when loading on submit, is to do the following:

  • Pass the form parameters to a servelt that I use to create an object.
  • Pass these same parameters to another servlet to be shown in a separate jsp.
  • I know there is a way to pass these parameters such as using a session variable, but as you know, it is not very advisable to use it.

        
    asked by anonymous 30.05.2017 / 22:35

    1 answer

    0

    You do not need two servlets, your problem is easier to resolve than this:

  • Send the values of your form to the servlet
  • Create its object in the servlet, persist it, make the magic happen
  • Place your object in the request, for example request.setAttribute("produto", produto);
  • Redirect to your jsp:

    RequestDispatcher rd = request.getRequestDispatcher("/produto.jsp"); rd.forward(request,response);

  • You now have access to the produto object that is in the request to expose the information you need.

        
    31.05.2017 / 12:08