I'm a little new to this.
What I want to do: Under Tomcat I want to check if a "开发者_开发知识库user_name" cookie exists within a webapp. If it does not I want to redirect to another site to set the cookie (same domain) and then redirect back to the requested page.
The service that I'm using to set the user_name cookie works fine, I just need to understand whether I can check for the cookie and redirect to that page if the cookie doesn't exist within my Tomcat config or if this check/redirect has to happen in the code for the webapp.
So:
If cookie user_name exists
run webapp
else
redirect to https://ServerToSetUser_id?http://myhost/userrequestedpath/
This is easy, and is not specific to Tomcat. It is part of the servlet spec, so works in any container. Your servlet/JSP has access to a request
object of type HttpServletRequest.
Call getCookies()
and iterate through the Cookie
s it returns to look for the one you want. If you find it, continue. If you don't, use sendRedirect("http://otherserver.com")
on HttpServletResponse to send your redirect and then finish your servlet/JSP processing.
精彩评论