Reputation: 2560
I have read many posts and blogs about rewriting and I know there is a difference between internal server rewriting and redirecting. I am interested in knowing how the internal rewriting works, and how this is done in Java. I am using PrettyFaces for my Java webapplication and it would have been great to know how (in very simple terms ofcourse) your able to look at the request before it is served. Is it a kind of filter that is invoked first?
And last, url rewriting on server is "program" that converts a URL in the rewrite rules to a real resource on the server right? This all happens internally so the user thinks that the address is for a "real" resource?
Thank you.
Upvotes: 1
Views: 1025
Reputation: 3191
I am using PrettyFaces for my Java webapplication and it would have been great to know how (in very simple terms ofcourse) your able to look at the request before it is served. Is it a kind of filter that is invoked first?
Yes, there is a Servlet Filter registered to trigger first in any ServletRequest. This filter intercepts the request and either redirects, forwards, or chains (does nothing.)
And last, URL-rewriting on server is "program" that converts a URL in the rewrite rules to a real resource on the server right? This all happens internally so the user thinks that the address is for a "real" resource?
That depends. If you use redirecting, then the user would know they have been moved to a different resource. However, using the default mapping functionality of PrettyFaces, a servlet Forward is used instead. This is completely hidden from external users.
One other thing that tools like PrettyFaces and OCPsoft Rewrite do, is outbound URL-rewriting, which is only possible with "internal server" rewriting tools. This means that they can also modify the URLs in your application's HTML response as well (which prevents incorrect links from being generated and sent to the user as text.)
I hope this is a helpful summary.
Upvotes: 2