I want to get the path variable in servlet. Assume the url is www.demo.com/123/demo
. I want to get the 123
value from the path without doing any string manipulation operation.
Note: the following servlet doesn't have any web.xml configurations. My code is:
@WebServlet(urlPatterns = { "/demo" })
public class DemoServlet extends HttpServlet {
public DemoServlet()
{
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doPost(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
sysout("demo");
}
}