I'm using jetty 9.0.3.
How to map an URL such as www.myweb.com/{servlet}/{parameter} to the given servlet and parameter?
For example, the URL '/client/12312' will route to clientServlet and its doGet
method will receive 12312 as a parameter.
I'm using jetty 9.0.3.
How to map an URL such as www.myweb.com/{servlet}/{parameter} to the given servlet and parameter?
For example, the URL '/client/12312' will route to clientServlet and its doGet
method will receive 12312 as a parameter.
You can use
Jersey
and register the following class in theResourceConfig
packages, which is handling../worker/1234
url patterns.read more: When to use @QueryParam vs @PathParam
You'll have 2 parts to worry about.
WEB-INF/web.xml
The pathSpec
In your
WEB-INF/web.xml
you have to declare your Servlet and your url-patterns (also known as the pathSpec).Example:
This sets up the servlet implemented as class
com.mycompany.ClientServlet
on the nameclientServlet
then specifies the url-pattern of/client/*
for incoming request URLs.The extra
/*
at the end of the url-pattern allows any incoming pattern that starts with/client/
to be accepted, this is important for the pathInfo portion.The pathInfo
Next we get into our Servlet implementation.
In your doGet(HttpServletRequest req, HttpServletResponse resp) implementation on ClientServlet you should access the req.getPathInfo() value, which will receive the portion of the request URL that is after the
/client
on your url-pattern.Example:
At this point you do whatever logic you want to against the information from the Path Info