• 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

using same value in multiple pages...

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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")%>
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
bhagath kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic