1

I have a jsp page with some java code and jsp functions. Please find the code below.

   <%
        try {
            client.removeOAuthApplicationData(consumerkey);
            String message = resourceBundle.getString("app.removed.successfully");
            CarbonUIMessage.sendCarbonUIMessage(message,CarbonUIMessage.INFO, request);
        } catch (Exception e) {
            String message = resourceBundle.getString("error.while.removing.app");
            CarbonUIMessage.sendCarbonUIMessage(message, CarbonUIMessage.ERROR, request,e);
            forwardTo ="../admin/error.jsp";
        }
    %>
    <script type="text/javascript">
        function forward() {
            alert('forward');
            location.href = "<%=forwardTo%>";
        }
        function createAppOnclick() {
            alert('testtt');
    }
</script>

<script type="text/javascript">
    createAppOnclick();
    forward();

</script>

I need to call createAppOnclick function once the java code finishes executing. Once I execute this it calls first the createAppOnclick function. I am bit new to javascript and jsp and appreciate your help.

Thanks

Hasanthi
  • 1,251
  • 3
  • 14
  • 30

1 Answers1

3

Javascript plays on client side and Java&JSP plays on server side.

What you can do is

Call your all javascript functions in your document load (onready) function so that they can execute while the page load.

You cannot run those functions on server.

Note : How to avoid Java code in JSP files?

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307