At first, a user would request a resource (a web page, an image or a video), and the server would return it; simple, but very limited because the webpages were static. With the growth of commercial activity on the Web, companies had to deliver dynamic content to their customers. So, they have to build dynamic web pages.
The first solution for creating dynamic content was the Common Gateway Interface (CGI). By using HTML pages and CGI scripts written in any number of languages (from Perl to Visual Basic), an application could access databases and serve dynamic content. Of course, CGI was too low level because you had to handle HTTP headers and call HTTP commands, and needed to be improved.
After the failure of applets to become widely adopted, Sun introduced servlets as a way to have thin, dynamic web clients. Servlets were an alternative to CGI scripts because they would offer a higher-level library for handling HTTP, had full access to the Java API (allowing database access, remote invocation, etc.), and could create HTML as a response to be displayed for the user. Sun released JSP in 1999 as an enhancement of the servlet model.
But, because JSPs were mixing Java and HTML code, in 2001 an open source framework arrived and opened doors to a new approach: Struts. This extended the servlet API and encouraged developers to adopt an MVC architecture. Recent history is full of other web frameworks, each trying to fill the gaps of the last (Tapestry, Wicket, WebWork, DWR, Spring MVC …).
Today, JSF 2.0 is the standard web framework in Java EE 6. It competes with Struts and Tapestry within the Java space. Rails and Grails compete with JSF overall, in the sense that Java competes with Ruby or Groovy. Google Web Toolkit (GWT), Flex, and JavaFX can be complementary to JSF.