java - Support for Dynamic path in URL with Nginx and Tomcat -


the use case trying implement.
display different content based on {{random_string}} in url path.
users see different content based on {{random_string}} url contains.

eg:

www.example.com/{{random_string}}/index.jsp 

the urls these below. ( include random characters before jsp)

www.example.com/xc/index.jsp
www.example.com/2b/index.jsp
www.example.com/43/index.jsp

my question

  1. how setup nginx , tomcat able support {{random_string}} in url without throwing 404?

my current environment/setup (this works fine)

nginx along tomcat. requests come nginx redirected tomcat access root.war e,g - www.example.com/index.jsp

you shouldn't have change in nginx or tomcat config. create servlet intercept requests , extract {{random_string}} before forwarding jsp. here basic steps:

1) create servlet url pattern of /* requests go it.

2) in servlet's doget() method, use request.getpathinfo() retrieve url path , parse extract {{random_string}}.

3) use request.setattribute() set attributes data want display in jsp page.

4) forward request jsp using requestdispatcher, e.g.:

requestdispatcher dispatcher = request.getrequestdispatcher("/index.jsp");   dispatcher.forward(request, response);   

5) in jsp, use request attributes have set in step 3 display content.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -