Passing Parameters between a jsp and two servlts?

Asked

Viewed 97 times

0

I have a doubt perhaps 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 question is this: There was a form in jps where what I want to happen when I press Submit is to do the following:

  1. Pass form parameters to a servelt I use to create an object.
  2. Pass these same parameters to another Servlet to be shown in a jsp part.

However, I know that 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.

  • I suggest using jQuery then

1 answer

0

You don’t need two Servlets, your problem is easier to solve than this:

  1. Send the values of your form to Servlet
  2. Create the respective object in Servlet, persist it, make the magic happen
  3. Put your object in the request, for example request.setAttribute("produto", produto);
  4. Redirect to your jsp:

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

Now you have access to the object produto who is in the request to expose the information you need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.