You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Unmesh Joshi <un...@gmail.com> on 2011/02/13 20:00:08 UTC

Registering sling servlet for resource

Hi,

I am trying to register a servlet for resource type, and its not
working. It works just fine if I register for path.

1. I have a component (JSP) in CQ as /test/login
2. I am having form as following
    <form method="POST" action="<%=resource.getPath() %>.html">
    <input name="someField" type="text">
    <input type="submit" value="submit"></input>
  </form>
3. I have a servlet registerd to handle POST request. The servlet is
registered for resource type as follows

 /* @scr.property name="sling.servlet.resourceTypes" value="test/login"*/

I expect that when the form is submitted, the servlet registered for
that resource type should be invoked. But its not working. Am I
missing something here?

Thanks,
Unmesh

Re: Registering sling servlet for resource

Posted by Unmesh Joshi <un...@gmail.com>.
Thanks!.

Adding

/*@scr.property name="sling.servlet.methods" value="POST"*/

 did the trick.

On Mon, Feb 14, 2011 at 1:43 AM, Alexander Klimetschek
<ak...@adobe.com> wrote:
> On 13.02.11 20:00, "Unmesh Joshi" <un...@gmail.com> wrote:
>>/* @scr.property name="sling.servlet.resourceTypes" value="test/login"*/
>
> If this is the complete javadoc annotations for the servlet class, then
> the following is missing:
>
> - @scr.component / @scr.service marking it as a component and service
> (providing an implementation for the javax.servlet.Servlet interface)
> - setting  the property "sling.servlet.methods" to handle POST requests
> (by default, I think it will only be called for GET requests)
>
> Hence you probably need:
>
> /**
>  * @scr.component metatype="false"
>  * @scr.service
>  * @scr.property name="sling.servlet.resourceTypes" value="test/login"
>  * @scr.property name="sling.servlet.methods" value="POST"
>  */
>
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> Developer // Adobe (Day) // Berlin - Basel
>
>
>
>
>

Re: Registering sling servlet for resource

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 13.02.11 20:00, "Unmesh Joshi" <un...@gmail.com> wrote:
>/* @scr.property name="sling.servlet.resourceTypes" value="test/login"*/

If this is the complete javadoc annotations for the servlet class, then
the following is missing:

- @scr.component / @scr.service marking it as a component and service
(providing an implementation for the javax.servlet.Servlet interface)
- setting  the property "sling.servlet.methods" to handle POST requests
(by default, I think it will only be called for GET requests)

Hence you probably need:

/**
 * @scr.component metatype="false"
 * @scr.service
 * @scr.property name="sling.servlet.resourceTypes" value="test/login"
 * @scr.property name="sling.servlet.methods" value="POST"
 */


Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel