13

Is it possible to redirect a user automatically to a second jsp page as soon as the home page loads?

IceNine
  • 205
  • 2
  • 5
  • 12
  • 1
    That wouldn't be done by the JSP. That is server side. You want client side behavior. Use javascript. I don't see the point however. Wouldn't you just want to send a redirect instead of ever hitting the first page? – Sotirios Delimanolis Sep 02 '13 at 15:04

2 Answers2

28

With core JSTL libraries loaded <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> you can use:

<c:redirect url="/home.html"/>
JohnMark13
  • 3,709
  • 1
  • 15
  • 26
  • can I see it being implemented somewhere? – KNU Jun 11 '14 at 18:54
  • 2
    Sure, all over the place. Did you look? Here is an example http://www.devmanuals.com/tutorials/java/jsp/jstl/CoreTagRedirect.html and another http://www.tutorialspoint.com/jsp/jstl_core_redirect_tag.htm and some notes from IBM http://www.ibm.com/developerworks/library/j-jstl0318/ – JohnMark13 Jun 16 '14 at 11:54
3

There is an example of such a thing: JSP - Page Redirecting

Simplest is using sendRedirect:

public void response.sendRedirect(String location)
throws IOException 
Zoe
  • 27,060
  • 21
  • 118
  • 148
  • 1
    Whilst this is the accepted answer, you should try hard to minimise the amount of scriptlets in your JSP as they inevitably add untestable complexity. If you need a tutorial which achieves the same thing using standard tag libraries see http://www.tutorialspoint.com/jsp/jstl_core_redirect_tag.htm – JohnMark13 Sep 02 '13 at 18:44