Sunday, July 18, 2010

Learning about ESP pages in Sling

Lately I've been doing a fair amount of server-side scripting using ESP (ECMAScript Pages) in Sling. At first blush, such pages tend to look a lot like Java Server Pages, since they usually contain a lot of scriptlet markup, like:

// script code here


// stuff to be evaluated here

So it's tempting to think ESP pages are simply some different flavor of JSP. But they're not. From what I can tell, ESP pages are just server pages that get handed to an EspReader before being served out. The EspReader, in turn, handles the interpretation of scriptlet tags and expression tags (but doesn't compile anything into a servlet). Bottom line, ESP is not JSP, and despite the availability of scriptlets tags, things work quite a bit differently in each case.

Suppose you want to detect, from an ESP page or a JSP page, what kind of browser a given page request came from. In a Sling JSP page you could do:

<%@taglib prefix="sling" uri="" %><%




java.util.Enumeration c = request.getHeaders("User-Agent");

String s = "";

while ( c.hasMoreElements() )

s += c.nextElement();


<%= s %>


But what do you do in ESP? Remember, <sling:defineObjects/> is not available in ESP.

It turns out that Sling automatically (without the need for any directives) exposes certain globals to the JavaScript Context at runtime, and one of them is a request object. Thus, in ESP you'd simply do:



s = "";

while ( c.hasMoreElements() )

s += c.nextElement();


<%= s %>

Very similar to the JSP version.

So the next question I had was, what are the other globals that are exported into the JavaScript runtime scope by Sling? From what I can determine, the Sling globals available in ESP are:


currentNode is the JCR node underlying the current resource; currentSession is what it sounds like, a reference to the current Session object; log refers to the org.slf4j.Logger; reader, I'm not sure about (is it a reference to the EspReader?); request is a reference to the SlingHttpServletRequest; resource is the current Resource; response is, of course, a reference to the SlingHttpServletResponse; and sling is a SlingScriptHelper. All of these are available all the time, throughout the life of any ESP script in Sling.

For more information, try the Sling Javadocs here or Day's page of resources here (note, in particular, the list of References on the right).


  1. I just have this energy level that I've never had before. The only thing that's changed is I've started wearing my Power Balance bracelet and nike running shoes
    Power Balance wholesale
    Silly Bands
    Reebok Easytone

  2. I just have this energy level that I've never had before. The only thing that's changed is I've started wearing my Power Balance bracelet and nike running shoes
    Power Balance wholesale
    Silly Bands
    Reebok Easytone

  3. perfect explanation about java programming .its very useful.thanks for your valuable training in chennai | java training in velachery


  4. very useful info, and please keep updating........
    Best Online Software Training

  5. perfect explanation about java programming .its very useful.thanks for your valuable information.
    GCLUB Casino
    GClub casino

  6. I just needed to record a speedy word to express profound gratitude to
    you for those magnificent tips and clues you are appearing on this
    site. Java and J2EE Training in Chennai | Java and J2EE Training Institutes in Chennai

  7. I read this article. I think You put a lot of effort to create this article. I appreciate your work.
    Dissertation Writing Services

  8. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    Best Hadoop training in chennai

  9. Thank you much for this tutorial; this is an informative and valuable blog. Visit for
    SEO Service in Delhi
    Web Development Company

  10. Informative article, this is just what I was looking for, thank you!!

    DevOps Online Training

  11. I simply want to tell you that I am just beginner to blogs and absolutely enjoyed you’re website. More than likely I’m planning to bookmark your blog . You really come with awesome stories.

    RPA Training in Chennai

    DevOps Training

  12. I accept there are numerous more pleasurable open doors ahead for people that took a gander at your site.we are providing ReactJs training in Chennai.
    For more details: ReactJs training in Velachery | ReactJs training in chennai


    you can search low-cost website with high-quality website functions.
    Today Join Us
    Call: +91 - 8076909847

    website development company in Delhi

    interior designers in delhi

    website designing company in delhi

    SEO service in Delhi

    Best It Service Provider:

    1. Website Designing And Development.
    2. SEO Services.
    3. Software Development.
    4. Mobile App Development.

  14. Very nice post. It’s really helpful for me. I definitely appreciate this site. Thanks for sharing...visit for
    web development company in noida

  15. Goyal packers and movers in Panchkula is highly known for their professional and genuine packing and moving services. We are top leading and certified relocation services providers in Chandigarh deals all over India. To get more information, call us.

    Packers and movers in Chandigarh
    Packers and movers in Panchkula
    Packers and movers in Mohali
    Packers and movers in Zirakpur
    Packers and movers in Patiala
    Packers and movers in Ambala
    Packers and movers in Ambala cantt
    Packers and movers in Pathankot
    Packers and movers in Jalandhar
    Packers and movers in Ludhiana

  16. This comment has been removed by the author.

  17. Thanks for such a great article here. I was searching for something like this for quite a long time and at last, I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays.Best RPA training in Chennai | RPA training in Chennai

  18. I am grateful to the owner of this site which really shares this wonderful work of this site.That is actually great and useful information.I'm satisfied with just sharing this useful information with us. Please keep it up to date like this.Thank you for sharing..

    website designing company in patna

    packers and movers in patna

    cctv camera dealers in patna

    jobs in patna

  19. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
    PHP Training in Chennai
    PHP Course in Chennai
    Web Designing Course in chennai
    Hadoop Training in Chennai
    German Language Classes in Chennai
    PHP Training in Porur
    PHP Training in Adyar

  20. hello sir,
    thanks for giving that type of information. Really enjoyed this blog post. Really looking forward to reading more. Much obliged.
    digital marketing company in delhi

  21. Nice and interesting post,I appreciate your hard work,keep uploading more, Thank you for sharing valuable information.
    App Development Company in Delhi

  22. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definitely interested in this one. Just thought that I would post and let you know. Nice! thank you so much! Thank you for sharing.
    Website Development Company in Delhi
    Website Designing Company in Delhi
    Mobile App Development Company
    Mobile App Development Company in India

  23. I feel happy about and learning more about this topic. keep sharing your information regularly for my future reference. This content creates a new hope and inspiration with in me. Thanks for sharing article like this. the information which you have provided is better then other blog.
    IELTS Coaching in Dwarka sector 7

  24. Awesome article, I will never comment on other blog, but I will deeply read your article and I am collect many information with your article, thank you so much for share this valuable information with us, I really like to read this type blog, keep sharing like this type useful information am suggest to my all dear friend to visit this blog and get collect this great information, thank you so much for read my comment, if any one searching the website designing and also PPC company in India please come on my website ogeninfo system we are completed all type digital marketing in cheap rate.
    Website Designing Company in India

  25. I feel happy to say this I will deeply learning your blog and it’s really useful for me, keep sharing like this type valuable information regularly, I like to thanks for sharing this superb blog I hope I see you soon again time, thank you so much for read my comment, if any one searching the shipping company in India please visit my website yhcargoindia, we are shift your all type product with care in cheap rate.
    Custom Broker in India

  26. Hello, I read your blog occasionally, and I own a similar one, and I was just wondering if you get a lot of spam remarks? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me insane, so any assistance is very much appreciated.
    Android Course Training in Chennai | Best Android Training in Chennai
    Datascience Course Training in Chennai | Best Data Science Training in Chennai

  27. Thanks for the article may be useful for everything
    Mobile App Development in Noida

  28. Replies
    1. Hi All,
      If any one is looking out for a SEO service provider in Delhi,NCR then I would like to share the name of I such company which ranked among the Top SEO services provider company in Delhi ( they are providing the best SEO service in Delhi, here you can get the best professional services within your budget and as per your given timeline this company is among one of the top most companies which provide SEO services in India as of now there Office is situated in East Delhi which is close to Nirman Vihar metro station.For more details please dial +919910326510 and get more insights concerning their charges, 100% satisfaction guaranteed.

      seo services in India

      seo company in delhi


  29. Thanks for the info And I hope to read this good article again.

    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    สมัครสมาชิกที่นี่ >>> Gclub online

  30. Thanks for the info And I hope to read this good article again.

    เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
    เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา สมัคร Gclub Royal1688
    และยังมีเกมส์สล็อตออนไลน์ 1688 slot อีกมากมายให้คุณได้ลอง
    สมัครสมาชิกที่นี่ >>> Gclub Royal1688

  31. Thank you so much for given such an informative blog. Get the best Website Designing and Development Services by Ogeninfo.
    Website Designing Company in Delhi

  32. Get the best performing Mutual Fund by Mutual Fund Wala and know the best investment schemes.
    Mutual Fund Agent

  33. Interesting information and attractive.This blog is really rocking... Yes, the post is very interesting and I really like it.I never seen articles like this. I meant it's so knowledgeable, informative, and good looking site. I appreciate your hard work. Good job.
    Kindly visit us @
    Sathya Online Shopping
    Online AC Price | Air Conditioner Online | AC Offers Online | AC Online Shopping
    Inverter AC | Best Inverter AC | Inverter Split AC
    Buy Split AC Online | Best Split AC | Split AC Online
    LED TV Sale | Buy LED TV Online | Smart LED TV | LED TV Price
    Laptop Price | Laptops for Sale | Buy Laptop | Buy Laptop Online
    Full HD TV Price | LED HD TV Price
    Buy Ultra HD TV | Buy Ultra HD TV Online
    Buy Mobile Online | Buy Smartphone Online in India

  34. Excellent and nice post. It will beneficial for everyone. Thanks for sharing such a wonderful post. I have discovered a standout among the best SEO company in Delhi( they are
    giving SEO services in Delhi, here you can get the best proficient administrations inside your financial plan and according to your given timetable this organization is among one of the top
    most seo company in laxmi nagar. Their Office is situated in East Delhi which is near Nirman Vihar metro station. For more subtleties please dial+919910326510 and get more experiences
    concerning their charges, 100% fulfillment. ensured.

    seo services in delhi
    best seo company in delhi
    seo company in delhi
    seo company in laxmi nagar


Add a comment. Registration required because trolls.