简体   繁体   中英

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. Here is my code on the servlet page.

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

And here is the code on the jsp page

This prints null value: <%=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.

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

and in JSP

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

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