O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The <jsp:forward> standard action

You CAN forward from one JSP to another. Or from one JSP to a servlet. Or from one JSP to any other resource in your web app.

Of course, you don’t usually want to do this in production, because if you’re using MVC, the View is supposed to be the View! And the View has no business doing control logic. In other words, it shouldn’t be the View’s job to figure out if the guy is logged in or not—someone else should have made that decision (the Controller), before deciding to forward to the View.

image with no caption

But let’s suspend all that good MVC judgement for the time being, and see how we could do it, if we were to forward from a JSP page to something else.

Why bother if you’ll never do it? Well, you might one day stumble on a problem where <jsp:forward> is a useful solution. More importantly, like a lot of what’s in the book (and the exam), the use of <jsp:forward> is outthere. Lurking in gazillions of JSPs that you might one day find yourself maintaining (or ideally refactoring).

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required