1

So I have this sample class:

public class SuperHero implements Serializable{

    private String firstName, lastName;
    private int age;
    // getters, setter etc..

Assume I have a superHero attribute in servletContext.

@Override
public void contextInitialized(ServletContextEvent sce) {
    final SuperHero superHero = new SuperHero("Koray", "Tugay", 31);
    sce.getServletContext().setAttribute("superHero", superHero);
}

This will work fine in a jsp file:

${superHero.firstName}
<br/>
${superHero.lastName}
<br/>
${superHero.age}

But in a Servlet I will need to cast it:

final SuperHero superHero = (SuperHero) getServletContext().getAttribute("superHero");

So who is actually doing the magic, the JSP or the {Expression Language}, and how does it work ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
  • 1
    The expression language uses [reflection](https://docs.oracle.com/javase/tutorial/reflect/). – JB Nizet Jan 29 '16 at 20:24
  • 1
    The expression language is doing the magic, by being a *dynamically typed* language, while Java is a *statically typed* language. You can google those terms to learn more. – Andreas Jan 29 '16 at 20:36

0 Answers0