I created a Servlet call ShippingDetailsServlet.java and deployed it. I need to submit a HTML form to it. I am not sure what path I should put in the form action. Below is the form.
<form action="/services/mycompany/ShippingDetailsServlet" method="post"> Country: <input type="text" name="country" value="au"><br> Quantity: <input type="text" name="quantity" value="1"> <cq:include path="./submit" resourceType="foundation/components/form/submit" /> </form>
Please let me know what path should I give for the form action so that it can be submitted to the Servlet.
Below is the Servlet.
package mycompany.servlets;
import org.apache.felix.scr.annotations.Properties; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.sling.SlingServlet; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.servlets.SlingAllMethodsServlet; import javax.servlet.ServletException; import java.io.IOException; import java.io.PrintWriter; @SlingServlet( paths={"/services/mycompany/"} ) @Properties({ @Property(name="service.pid", value="mycompany.ShippingDetailsServlet",propertyPrivate=false), @Property(name="service.description",value="Shipping details servlet", propertyPrivate=false), @Property(name="service.vendor",value="mycompany", propertyPrivate=false) }) public class ShippingDetailsServlet extends SlingAllMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { //Do something fun here } @Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { //Do something fun here PrintWriter out = response.getWriter(); out.println("Hello"); } }
Solved! Go to Solution.
Hi,
if you have annotated your servlet like this:
@SlingServlet(methods = { "POST" }, paths = "/apps/mycompany/servlets/GenericServlet")
the form shoud post to the same same url as in paths, that is "/apps/mycompany/servlets/GenericServlet"
so if you would change you "paths" line in the servlet to "/services/mycompany/ShippingDetailsServlet"
the form would post to that one.
Good Luck
/Johan
Hi,
if you have annotated your servlet like this:
@SlingServlet(methods = { "POST" }, paths = "/apps/mycompany/servlets/GenericServlet")
the form shoud post to the same same url as in paths, that is "/apps/mycompany/servlets/GenericServlet"
so if you would change you "paths" line in the servlet to "/services/mycompany/ShippingDetailsServlet"
the form would post to that one.
Good Luck
/Johan
Thanks a lot Johan for the quick reply. It works.
Views
Replies
Total Likes
Here is a community article that talks about Sling servlets and AEM:
http://scottsdigitalcommunity.blogspot.ca/2013/06/posting-form-data-to-adobe-cq-using.html
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies