Posts Tagged “Apache Sling Servlet”

CQ Resource Inclusion from a Servlet

Including resources from a JSP is super simple due to the many facilities within Sling and CQ.  But what if you wanted to include a CQ resource from a custom Sling Servlet?  All of this nice JSP based inclusion is built on top of the JavaEE API.  Take a look at the class: javax.servlet.jsp.PageContext and two of it's methods: public abstract void include(String relativeUrlPath) and public JspWriter pushBody(Writer writer). These two method will form the basis for all...

Servlets in Sling - the case of the disappearing Servlet path

I have to admit, coming from a plain old JavaEE background, I was very dubious over the prospect of not using a Servlet path when creating custom Sling Servlets.  What - no Servlet path?  How will I access my Servlet?  New ideas always go down hard, but once I saw the light, it ALL made sense.Some folks have been evangelizing the use of Sling Servlets that are resource defined as opposed to path defined.  This...

END Form component is not delivered by the CQ elves...

I have long wondered how that stupid 'end' Form component shows up when you drop a 'start' Form component on a page.  Just like magic, that little bugger appears out of the ether.  The secret to this one is no longer a secret to you or me.Shame on me, and please forgive me, I did not write down the exact method I used to find this.  When I am "in the zone" hunting for something...

Handling File Upload in Adobe CQ

You need to handle a file upload in Adobe CQ.  So, you notice CQ already has Apache Commons FileUpload installed, so you decide to use it to handle the file upload.You write your servlet code and end up with something like this:// Check that we have a file upload requestfinal boolean isMultipart = ServletFileUpload.isMultipartContent(request);PrintWriter out = null;try {  out = response.getWriter();  if (isMultipart) {    // Create a new file upload handler    final ServletFileUpload upload =...

2 SlingHttpServletRequests walk up to a WhiteBoard...

Recently while creating a Servlet - which I have done hundreds of times on many a CQ based projects - the Default Get Servlet was getting resolved for my request.  I added logging, made sure the SCR name property was populated, round and round I go...  Unlike Stewart the GEICO mascot, I was not yelling "Weee!"  Quite the opposite.After bugging my compadre to have an extra set of eyes on the problem, and check to...