• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

request object in multiple jsp pages

 
Ranch Hand
Posts: 47
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

if i have 4 jsp pages viz 1.jsp, 2.jsp, 3.jsp & 4.jsp

1.jsp uses form parameter say "one" & after submit calls 2.jsp
2.jsp uses form parameter say "two" & after submit calls 3.jsp
3.jsp uses form parameter say "three" & after submit calls 4.jsp

if i want to refer the all jsp pages parameters in 4.jsp by giving
<%=request.getParameter("one") %>
<%=request.getParameter("two") %>
<%=request.getParameter("three") %>

it shows NULL for all ?

Secondly
if instead of using form submit, i use say <jsp:forward page="<jsp page name>" />
it also shows NULL for all ?

If request object is same in Submit & jsp:forward dispatching, then why it reports NULL.

Also even if i use request.setAttribute("attr","value") in 1.jsp.
in 4.jsp request.getAttribute("attr") show Null ?

i am bit confused with this behavior.

please help me to understand the request dispatching behavior after submit & jsp:forward actions.

Many Thanks
Regards
Vj


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you expect the request parameter to be carried across multiple submits?

If you want to accumulate the values and carry them forward, use hidden inputs to capture the values so that they are resubmitted with each subsequent form.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it shows NULL for all ?


in 4.jsp only the parameters are available that get submitted by 3.jsp; all others are long forgotten. If you need those, then you need to include them in the form in 3.jsp as hidden parameters.

If request object is same in Submit & jsp:forward dispatching, then why it reports NULL.


It's not the same object; each new request results in a new request object being created.
 
vijay dadhwal
Ranch Hand
Posts: 47
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the Reply Sir,

If i have understood correctly :-

(1) Submit() action carries request object only with current page <Form Parameters> and discards any previous <Form parameters>.
(2) jsp:forward action carries only earlier and current setAttributes in request object.

My questions are :-
(1) why do submit() action request object only carries Form parameters but not setAttributes() of the current page ?
(2) if request object does not change in jsp:forward action for muliple pages then why it does not carry default Form Parameters ?

Awaiting your valuable replies
Regards
vj
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

(2) jsp:forward action carries only earlier and current setAttributes in request object.

A forward retains whatever parameters the current request contains, as well as the attributes set by the code so far.

(1) why do submit() action request object only carries Form parameters but not setAttributes() of the current page ?


Request parameters and request attributes are different concept; there is no direct connection between them. I don't understand the question, though: A request object contains the form parameters of the current request, as well as any attributes the code sets. What else are you looking for?

(2) if request object does not change in jsp:forward action for muliple pages then why it does not carry default Form Parameters ?


What do you mean by "default" from parameters? Can you give an example of the specific control flow you're asking about? Meaning, which pages, which parameters, from where to where does the forward occur, and how does it work differently than what you expect?
 
vijay dadhwal
Ranch Hand
Posts: 47
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Here is the sample code of jsp's with queries :-

For Submit() Action
1.jsp
<%request.setAttribute("new","value");%>
<html>
<form method="post" action="2.jsp">
<input type="hidden" name="one" value="first">
<input type="submit" name="click">
</form>
</html>

For jsp:forward Action
1.jsp
<%request.setAttribute("new","value");%>
<html>
<form>
<input type="hidden" name="one" value="first">
</form>
<jsp:forward page="2.jsp" />
</html>

2.jsp
<%=request.getParameter("one")>
<%=request.getAttribute("new")>

Queries :-
For Submit() action from 1.jsp to 2.jsp, why <%=request.getAttribute("new")> returns NULL, although request.getParameter("one") is ok ?
For jsp:forward action from 1.jsp tp 2.jsp, why <%=request.getParameter("one") returns NULL, although request.getAttribute?("new") is ok ?

Regards
vj
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

For Submit() action from 1.jsp to 2.jsp, why <%=request.getAttribute("new")> returns NULL, although request.getParameter("one") is ok ?


The attribute is set when that JSP code is executed - long before the form is submitted (which will lead to a new and a different request object being created). There's a trip from the server back to the client and back to the server in between 1.jsp and 2.jsp.

For jsp:forward action from 1.jsp tp 2.jsp, why <%=request.getParameter("one") returns NULL, although request.getAttribute?("new") is ok ?


Forwards do not cause forms to be submitted (they're server-side operations), so whatever form elements are contained in that JSP will have no values.

I suggest to go through a JSP tutorial that explains these concepts; they're really fundamental to using JSPs.
 
vijay dadhwal
Ranch Hand
Posts: 47
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a ton Sir.

I got my answer, I hereby close this thread.

Regards
vj
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Removed. Please do not ask the same question more than once.]
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic