Support for Dynamic path in URL with Nginx and Tomcat
The use case I am trying to implement.
Display different content based on the {{random_string}} in the URL path.
Users will see different content based on the {{random_string}} that the URL contains.
eg:
www.example.com/{{random_string}}/index.jsp
The URLS will look like these below. ( They include random characters before the JSP)
www.example.com/xc/index.jsp
www.example.com/2b/index.jsp
www.example.com/43/index.jsp
My question
My Current Environment/Setup (this works fine)
Nginx along with Tomcat. Requests that come to nginx are then redirected to tomcat to access ROOT.war e,g - www.example.com/index.jsp
You shouldn't have to change anything in Nginx or Tomcat config. What you could do is to create a servlet that will intercept the requests and extract the {{random_string}} before forwarding to the JSP. Here are the basic steps:
1) Create a servlet with a URL pattern of /*
so that all requests go to it.
2) In the servlet's doGet()
method, use request.getPathInfo()
to retrieve the URL path and parse it to extract the {{random_string}}.
3) Use request.setAttribute()
to set attributes for the data you want to display in the JSP page.
4) Forward the request to the JSP using a RequestDispatcher, eg:
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
dispatcher.forward(request, response);
5) In the JSP, use the request attributes that you have set in step 3 to display the content.
链接地址: http://www.djcxy.com/p/89066.html上一篇: 更改Tomcat基本URL