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
%>

and

<%=
// 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="http://sling.apache.org/taglibs/sling/1.0" %><%

%><sling:defineObjects/>

<html><body>

<%

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

String s = "";

while ( c.hasMoreElements() )

s += c.nextElement();

%>


<%= s %>

</body></html>

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:



<%

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

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
currentSession
log
out
reader
request
resource
response
sling


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).

69 comments:

  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

    ReplyDelete
  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

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

    ReplyDelete

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

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

    ReplyDelete
  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

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

    ReplyDelete
  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

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

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

    DevOps Online Training

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  13. THANKS FOR INFORMATION

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

    website development company in Delhi

    levantro
    interior designers in delhi


    livewebindia
    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.

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

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

    ReplyDelete
  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 (www.nexcuit.com) 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

      Delete

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

    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
    สมัครสมาชิกที่นี่ >>> Gclub online

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

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

    ReplyDelete
  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

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

    ReplyDelete
  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

    ReplyDelete
  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(www.nexcuit.com) 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

    ReplyDelete
  35. 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 would also like to share some useful information.If
    you are Looking for the satta result Delhi Darbar in delhi,ncr or satta result Gali, satta result Deshawar. Then open the below link for more details.

    satta result Taj
    satta result Delhi Darbar
    satta result Gali
    satta result Deshawar
    Disawar Satta Result
    satta result Ghaziabad
    satta result Faridabad

    satta king shri ganesh
    satta result chart
    satta king chart
    satta king result
    satta bazar result

    ReplyDelete
  36. Thank you for sharing your awesome and valuable article this is the best blog for the students they can also learn.
    Workday Online Training

    ReplyDelete
  37. Decent information put in this blog, thank you so much for sharing such amazing information.
    Lifestyle Magazine

    ReplyDelete
  38. Thanks for giving that type of information. Really enjoyed this blog post. I would also like to share some useful information.If you are Looking for the satta result Delhi Darbar in delhi,ncr or
    satta result Gali, satta result Deshawar. Then open the below link for more details.

    satta king Faridabad satta king Gali satta king Desawar

    ReplyDelete
  39. 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 would also like to share some useful information
    regarding digital marketing company in delhii(www.nexcuit.com)This is the digital marketing company in delhi located in Laxmi Nagar, East Delhi. So if anyone is looking out for the Best SEO company in Delhi then reach out to them on the given number+919910326510 and get more details.related to the packages they offer and their prices. One thing I can bet on is that you will get 100% satisfaction from there services.
    digital marketing company in delhii
    Best Digital marketing agency serving in Delhi
    best digital marketing company in Delhi NCR
    SEARCH ENGINE OPTIMIZATION (SEO)

    ReplyDelete
  40. Excellent and nice post. It will beneficial for everyone. Thanks for sharing such a wonderful post. I have found one of the best digital marketing company in Delhi (www.nexcuit.com), 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 digital marketing services in India as of now Our 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.
    digital marketing company in delhi
    Best Digital marketing agency serving in Delhi
    best digital marketing company in Delhi NCR
    SEARCH ENGINE OPTIMIZATION (SEO)

    ReplyDelete
  41. The article is very interesting and very understood to be read, may be useful for the people. I wanted to thank you for this great read!! I definitely enjoyed every little bit of it. I have to bookmarked to check out new stuff on your post. Thanks for sharing the information keep updating, looking forward for more posts..
    Kindly visit us @
    Madurai Travels
    Best Travels in Madurai
    Cabs in Madurai
    Tours and Travels in Madurai

    ReplyDelete
  42. Excellent Blog. I really want to admire the quality of this post. I like the way of your presentation of ideas, views and valuable content. No doubt you are doing great work. I’ll be waiting for your next post. Thanks .Keep it up!
    Kindly visit us @
    Luxury Packaging Box
    Wallet Box
    Perfume Box Manufacturer
    Candle Packaging Boxes
    Luxury Leather Box
    Luxury Clothes Box
    Luxury Cosmetics Box
    Shoe Box Manufacturer
    Luxury Watch Box

    ReplyDelete
  43. Trutech Products stand ahead in the queue of leading Transformer Manufacturers In Pune and can be reached for delivering heavy-duty and durable transformers. We aim to provide quality and reliability in the products we manufacture and our clients assure that they are served with the same. Be one of our clients and give us a chance to serve you.

    ReplyDelete
  44. I really like you post,Thanks for your sharing.

    Gclub
    Gclub Casino

    ReplyDelete

Add a comment. Registration required because trolls.