Jitendra
Jitendra

Reputation: 53

How to configure custom servlet in magnolia CMS

I am trying to do registration example in magnolia. I have a registration form, on submission of form control should be transferred to my own written servlet.

snippet for form :

   <body>
        <form action="./register" method="post">
            Name:<input type="text" name="name"><br />
             Email Id:<input type="text" name="email"><br/>
             <input type="submit"   value="Register">
        </form>
    </body>

Registration servlet class:

public class Registration extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        System.out.println("This is registration servlet");
    }

}

I have configured module descriptor :

<servlets>
  <servlet>
    <name>RegistrationServlet</name>
    <class>com.rbt.registration.Registration</class>
    <comment>registration servlet</comment>
    <mappings>
      <mapping>/register</mapping>
    </mappings>
  </servlet>
</servlets>

and I have also configured template definition. But when I click on submit button. It shows error that resource not found. Please help me.

Upvotes: 2

Views: 1332

Answers (2)

jox
jox

Reputation: 2368

The mapping you configured in the module descriptor will be relative to your context path. E.g. if your base url is http://example.com:8080/public ('public' being your context path), then your servlet will responding to http://example.com:8080/public/register.

Check if that url matches the url your form is submitting to. The action="./register" is a relative path and will depend on the path of the page that contains the form.

Upvotes: 0

Jan
Jan

Reputation: 4369

In your template, when writing html for the form you can also use action="${ctx.contextPath}/register" to have form response directed to uri on which servlet is listening. Also please go to config:/server/filters/servlets/ and verify that RegistrationServlet is correctly add there. Same problem (although for different servlet) was also discussed at Magnolia Forum

HTH, Jan

Upvotes: 2

Related Questions