简体   繁体   English

尝试将值从servlet传递到jsp页面

[英]Trying to pass a value from a servlet to jsp page

I'm trying to pass a value from a servlet java page to a jsp page, by using session. 我试图通过使用会话将值从servlet Java页传递到jsp页。 Here is my code on the servlet page. 这是我在servlet页面上的代码。

session.setAttribute ( "SPONSOR_ID", loginSponsorID ) ;
request.getRequestDispatcher("summary.jsp").forward(request, response);

And here is the code on the jsp page 这是jsp页面上的代码

This prints null value: <%=request.getAttribute("SPONSOR_Name")%>. 这将输出空值: <%=request.getAttribute("SPONSOR_Name")%>.

I get errors when I try assigning the return value into a variable. 尝试将返回值分配给变量时出现错误。

<c:set var=intMethod value"${'<%=request.getAttribute("SPONSOR_Name")%>'}"/>

I think you have typo, you set value in session but trying to read from request. 我认为您有错别字,您在会话中设置了值,但尝试从请求中读取。 make these two calls in sync, use either session or request. 同步进行这两个呼叫,使用会话或请求。

Hopes this is the problem; 希望这是问题所在; You have setted SPONSOR_ID and trying to retrieve SPONSOR_Name. 您已经设置了SPONSOR_ID并尝试检索SPONSOR_Name。

HttpSession session = request.getSession(true);
session.setAttribute("SPONSOR_ID", loginSponsorID);

and in JSP 在JSP中

<%= session.getAttribute( "SPONSOR_ID" ) %>

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

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