我创建了一个 Servlet 调用 ShippingDetailsServlet.java 并部署了它。我需要向它提交一个 HTML 表单。我不确定应该在表单操作中放置什么路径。下面是表格。
<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" />
请让我知道我应该为表单操作提供什么路径,以便可以将其提交给 Servlet。
下面是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");
}
}