1

I use this script in my JSP to perform via timeout a redirect after 5 seconds.

<script type="text/javascript">
    function redirect() {
        location.href = "registrazione.jsp";
    }
    window.setTimeout("redirect()", 5000);
</script>

I'm trying to eliminate any script in my web application. Is there a way to do this using JSTL or is there a specific tag library that I can download and use for this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
paolo2988
  • 857
  • 3
  • 15
  • 31

1 Answers1

0

You need to understand that JSP/JSTL runs in webserver and that JavaScript runs in webbrowser.

In order to be able to send a redirect from the webserver, you need to have a HTTP response. In order to have a HTTP response, you have to retrieve a HTTP request. In order to have a HTTP request, the client has to send it somehow; by clicking a link, submitting a form, changing the URL in browser's address bar, executing JavaScript window.location, executing JavaScript XMLHttpRequest, etc.

In other words, you can't send a redirect using JSP/JSTL without that the client has sent a HTTP request in some way. So, it's end of story.

Your JavaScript approach is really the best you can get to achieve the concrete functional requirement. I do therefore not understand your aversion against it and that you need to replace it by JSP/JSTL. Are you sure that you aren't confusing "JSP scriptlets" with "JavaScript"? The former is indeed a bad way of writing JSPs, but that's definitely not the same as JavaScript.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555