Suppose i'm having 2 jsp pages, page1 and page2. Now i'm including page1 in page2. I want to access some value from page1 and i want to access it within jsp scriplet tag, how can i get it without using cookie or session?
Asked
Active
Viewed 428 times
1 Answers
0
You cannot access variables declared in a scriptlet in page1 from page2. This is one of the disadvantages of scriptlets. Check out the answer by BalusC.
If you are using JSTL, you can do something like this in page1:
<c:set var = "salary" scope = "session" value = "666"/>
or with request scope:
<c:set var = "salary" scope = "request" value = "666"/>
And in page2:
<c:out value = "${salary}"/>
But really, you should be setting variables in your servlets which you can then access anywhere in the JSPs.. The use of scriptlets is highly discouraged.

Jonathan Laliberte
- 2,672
- 4
- 19
- 44
-
1Using JSP bean is better option then? – Desmond Aug 26 '17 at 18:16
-
If you want to, but generally you should use scriptlets as little as possible, or avoid it completely if you can. – Jonathan Laliberte Aug 26 '17 at 19:25