简体   繁体   中英

passing value from one jsp file to another jsp file

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM