javascript - URL Routes with Java Servlets -
i wanted know if there way similar code in java servlet in express.js
in express can example:
app.get('/:name',function(bla bla)){} the :/name parameter in url of can
localhost/kevin localhost/joe or whatever... great because can take example name (request.params.name) , it. , great because there no limit(as far know) how many routes can create, serves placeholder.
is there way can using java servlets?? want able have html page when click button goes localhost/button1 if click button goes localhost/button2.. , on.. i'm letting user create buttons dynamically don't want create jsp pages beforehand, want servletto create one..?
thanks
almost. of prefix mapping /foo/* , httpservletrequest#getpathinfo().
@webservlet("/name/*") public class nameservlet extends httpservlet { @override protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { string name = request.getpathinfo().substring(1); // ... } } invoke as
you can optionally map servlet on /*, act global front controller isn't idea you'd have take static resources css/js/images , such account.
in case intend create rest service, rather @ jax-rs instead of "plain vanilla" servlets. further reduce boilerplate code. see a.o. servlet vs restful.
Comments
Post a Comment