File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes transfer a variable from one jsp to another on button click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "transfer a variable from one jsp to another on button click" Watch "transfer a variable from one jsp to another on button click" New topic
Author

transfer a variable from one jsp to another on button click

narayana Ega
Greenhorn

Joined: Aug 23, 2012
Posts: 26
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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jul 26, 2007
Posts: 157
    
    1

you can also use hidden form field.
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 144
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:



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: transfer a variable from one jsp to another on button click