Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How to pass String Array Obj from one jsp to another jsp?

  Asked By: Rabiah    Date: Jun 13    Category: Java    Views: 11069
  

i want to pass a number of String Array Object from
one jsp file to another jsp file.will u please tell me
the way.ie

i have one file abc.jsp

in that i have String
x[]=request.getParameterValue("city");

on the submit of this file i want to pass the "x"
String array to another file..

how do i pass..please help me..

Share: 

 

12 Answers Found

 
Answer #1    Answered By: Abbas Hashmi     Answered On: Jun 13

Just put the string  into an hidden field in form. by concatinating all contents
into one string.

 
Answer #2    Answered By: Jana Franklin     Answered On: Jun 13

in second jsp  file u have to write the code following
<%
for(int i=0;i<x.length;i++){
%>
<input type="hidden" name="city" value="<%=x[i]%>">
<%}
%>

in third jsp file  u have to write the following code

x[]=request.getParameterValue("city");

 
Answer #3    Answered By: Clay Cook     Answered On: Jun 13

u can put the value of the string  object in to session
and get that value in another page.

 
Answer #4    Answered By: Josephine Gomez     Answered On: Jun 13

you can use session.setAttribute("X", x ); in abc.jsp

and in the next file  use String[] x = session.getAttribute("X");

I'm pretty sure it would work like this in concept. I know setAttribute sets an
Object so you'd just have to get it and probably cast it in the next file.

 
Answer #5    Answered By: Aadi Martin     Answered On: Jun 13

We can pass  String Array Objects from One jsp  to another using session
objects.. Session objects are used to pass values between jsp pages..
You can also use QueryString method..But it is not a good one.. Use
session objects always (Eventhough they will eat performance if they are
more)


Just see the Example..


First.jsp
---------
<%
String[] arg={"krish","ghfds"}; session.setAttribute("arg",arg); %>

Second.jsp
----------
<%
String[] arg=(String[])session.getAttribute("arg");
%>
<%=arg[0]%>
<%=arg[1]%>

 
Answer #6    Answered By: Jawwad Akram     Answered On: Jun 13

You never use nonfinal static class variables in servlets/jsp as when there are
multiple users there will be conflicts. Use the "request" object  or "session"
object.

 
Answer #7    Answered By: Shirley Allen     Answered On: Jun 13

You can do it by setting the x[] in the session in the
first jsp.

session.setAttribute("myArray", x);

and
while in another jsp  you can get it..

Object[] x = (Object [])
system.getAttribute("myArray");

 
Answer #8    Answered By: Myrna Brown     Answered On: Jun 13

You Can Even Do It By Making That Array as Static

 
Answer #9    Answered By: Reginald Thomas     Answered On: Jun 13

but how do i make the Static String Array object  in a
next page..

will u tell me in details..

 
Answer #10    Answered By: Seth Anderson     Answered On: Jun 13

Once u Make a Variable as Static U Can Access that variable Across the Jsp's
MoreOver U don't Need any Class Instance to Acess That Variable
I Did These funda with HashTable
If U Still Have Any Problem U can Revert Back

 
Answer #11    Answered By: Jeanne Lawson     Answered On: Jun 13

your concept is right but how do i implement it..i am
trying it on two jsp  pages but its shows null values
in second page.

 
Answer #12    Answered By: Reamonn Fischer     Answered On: Jun 13

You can have a flag, which is set when ActionListener
is called and in the paint method check this flag and
if it is set then call the your method and reset the
flag...

 




Tagged: