简体   繁体   English

将值从一个jsp文件传递到另一个jsp文件

[英]passing value from one jsp file to another jsp file

Suppose i'm having 2 jsp pages, page1 and page2. 假设我有2个jsp页面,即page1和page2。 Now i'm including page1 in page2. 现在,我将page1包括在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? 我想从page1访问一些值,并且想在jsp scriplet标记中访问它,如何在不使用cookie或会话的情况下获取它?

You cannot access variables declared in a scriptlet in page1 from page2. 您无法从page2访问page1的scriptlet中声明的变量。 This is one of the disadvantages of scriptlets . 这是scriptlet缺点之一 Check out the answer by BalusC. 查看BalusC的答案。

If you are using JSTL, you can do something like this in page1: 如果您使用的是JSTL,则可以在第1页中执行以下操作:

  <c:set var = "salary" scope = "session" value = "666"/>

or with request scope: 或具有请求范围:

  <c:set var = "salary" scope = "request" value = "666"/>

And in page2: 在第2页中:

<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. 但实际上,您应该在servlet中设置变量,然后可以在JSP中的任何位置访问这些变量。强烈建议不要使用scriptlet。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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