galgow
galgow

Reputation: 35

How should I do to send data between two jsp with a servlet

I want to display something from one jsp page in another jsp page by clicking a button. I did it using request.setAttribute request.getAttribute but it doesn't work for me, for some reason the variable I send is null or the page is blank.

Upvotes: 0

Views: 410

Answers (2)

www.hybriscx.com
www.hybriscx.com

Reputation: 1129

From your original question : When you are doing setAttribute(), its scope is limited to the request when the main page is loading and hence will not be available on the next page as it will be a new request.

<%Object product=ptp;
                   request.setAttribute("purchase", ptp.getId());
          %>

What you can do is, submit this value in URL param as GET or in a form (get/ post) to fetch it on next JSP using request.getParameter().

Or you can use session scope by session.setAttribute()

Hope it helps

Upvotes: 1

Mounir Messaoudi
Mounir Messaoudi

Reputation: 373

you can pass the variables through request scope or session scope.

request.setAttribute("variable name","value of its");

session.setAttribute("variable name","value");

Here a detailed exmple http://www.jsptut.com/sessions.jsp

Upvotes: 1

Related Questions