Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

transfer a variable from one jsp to another on button click

 
narayana Ega
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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....

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • 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.
 
harshvardhan ojha
Ranch Hand
Posts: 157
1
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can also use hidden form field.
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • 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:



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic