my dog learned polymorphism*
The moose likes JSP and the fly likes using same value in multiple pages... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "using same value in multiple pages..." Watch "using same value in multiple pages..." New topic
Author

using same value in multiple pages...

bhagath kumar
Greenhorn

Joined: Sep 23, 2004
Posts: 9
Hi I am new to JSP...

I obtain a value in one jsp after a lot of computing and I want to use this value in a diffrent JSP page, but dont want to comute it again, how can I use this value in another JSP page.

Bhagath.
Priya Murthy
Greenhorn

Joined: Sep 24, 2004
Posts: 3
Put this value in a session variable.

JSP1:
session = request.getSession();
session.setAttribute("aaa")=abc;

In JSP2:
session = request.getSession();
session.getAttribute("aaa");
bhagath kumar
Greenhorn

Joined: Sep 23, 2004
Posts: 9
can i pass string like that cause whe ni do the following

session = request.getSession();
session.setAttribute("rem")=strURL; (strURL is a String)

I get errors saying
1. left had side must be variable
2.can not convert from string to void
3.method setAttribute not applicable to strings.

Bhagath
Priya Murthy
Greenhorn

Joined: Sep 24, 2004
Posts: 3
are u putting ur code in <% %> paranthesis.

And please do it this way:

<%
session = request.getSession();
session.setAttribute("a" , "abc");
%>

iN JSP2:
<% String str =session.getAttribute("a")%>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

bhagath, please do some thinking on your own and not just blindly copy example code. Of course you need to use appropriate Java notation:



Priya, please be more careful when posting coding examples.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
bhagath kumar
Greenhorn

Joined: Sep 23, 2004
Posts: 9
I used the code given as below, as suggested in jsptut.com

First JSP: (i am not getting strURLrem from a text box but it is a string that is generated by various concatinations)

String name1 = request.getParameter( "strURLrem" );
session.setAttribute( "theName", name1 );

Second JSP:
strURL = session.getAttribute( "theName" ) ;

the second jsp gives error: (type mismatch: cannot convert from object to String)

and I am using this code in a <% %>

Bhagath.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Before delving into JSPs, I'd get a little bit of Java experience under my belt.

You are storing a String, yet the getAttribute() method returns an Object.

How would you deal with this situation if this were in a Java class? (Which in fact, it is -- JSP is merely a templating mechanism for automatically creating Java servlets on your behalf).
bhagath kumar
Greenhorn

Joined: Sep 23, 2004
Posts: 9
thanks for ur help, looks like i have to brush up java before anything else.

can i do a .toString() to make it work.

will research that, thanks much
 
 
subject: using same value in multiple pages...
 
Similar Threads
to print the value from a javascript function
passing value by hyperlink
returning value from jQuery
Jsp & JavaScript
How to Get Valueof SelectField