This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JSP and the fly likes Problem using Expression language in JSP page (java code) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem using Expression language in JSP page (java code)" Watch "Problem using Expression language in JSP page (java code)" New topic

Problem using Expression language in JSP page (java code)

Akmal Bajwa

Joined: Jul 18, 2011
Posts: 3
i am in great trouble. problem is i create a Servlet and code is

HttpSession session = request.getSession();
session.setAttribute("employee", employee);

"employee" is bean and now i am access that in jsp page like this:

<LI><B>First Name:</B> ${}

it work fine but if i use this bean in java code, it return null value like this:

<LI><B>First Name:</B> <%= pageContext.getAttribute("") %>

my requirement is that i have to use it in java code not simple html second one thing more if i do this code in Servlet:

session.setAttribute("attribute2", "USA");

and use this code in jsp:

<LI><B>attribute1:</B> <%= pageContext.findAttribute("attribute2") %>

so this code work fine but problem with bean so kindly help me. my need is get expression value in variable in java code in jsp

Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

<LI><B>First Name:</B> <%= pageContext.getAttribute("") %>

this would search for attribute in pageContext for name "".

Try using <jsp:getProperty> method or use Expression Language for same

Ashwin Sridhar
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63052

You should no longer be using scriptlets and scriptlet expressions. They have been discredited for almost 10 years now.

Use the JSTL and EL instead.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Problem using Expression language in JSP page (java code)
It's not a secret anymore!