• 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

transfer a variable from one jsp to another on button click

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Her I want to transfer the variable "s" from the first jsp file to second jsp file

first.jsp:

s="hi";
<form action="Button.jsp" method="get" name="value">
<button type="submit" >Older Versions</button>
</form></center>

Second.jsp:

<%
String s=(String)request.getAttribute("value");
%>

<br><br><br><br><br>
<center><h1>The Older Version Of Aggregate are:
<%out.println(" "+s);%>
</h1></center>

can any one help me to transfer the "S" to second jsp and printing that....

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dont directly submit jsp to another jsp. introduce servlet in between that.
to transfer your value you need to tie the value to html tags. for instance use hidden html tag in html form to submit the value to servlet.
and in servlet get the value using request#getParameter. and set the value in any one of the scope(preferably request)and forward to Second.jsp

in Second.jsp you read/print the value.

P.S: there are many ways to do this. the above flow is just one of them.
 
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can also use hidden form field.
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Narayana,

i think i did it in the below way. i think this might be helpful and not pretty sure if this is what you are expecting. please let me know if so.
replace your code with the below one.


first.jsp:



second.jsp:



 
Maybe he went home and went to bed. And took this tiny ad with him:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic