• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem using Expression language in JSP page (java code)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
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> ${employee.name.firstName}

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("employee.name.firstName") %>

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

thanks,
Akmal
 
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



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

Try using <jsp:getProperty> method or use Expression Language for same
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Let nothing stop you! Not even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic