• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using same value in multiple pages...

 
bhagath kumar
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Priya Murthy
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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")%>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic