在Java代码之后调用Javascript函数 [英] Call Javascript function after java code

查看:94
本文介绍了在Java代码之后调用Javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一些Java代码和jsp函数的jsp页面.请在下面找到代码.

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>

我需要调用一次createAppOnclick函数 Java代码完成执行.一旦执行此命令,它将首先调用createAppOnclick函数.我对javascript和jsp还是陌生的,感谢您的帮助.

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.

谢谢

推荐答案

JavaScript在客户端发挥作用,而Java&JSP在服务器端发挥作用.

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

您可以做的是

在文档加载(就绪)函数中调用所有javascript函数,以便它们可以在页面加载时执行.

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.

注意: 如何避免Java代码在JSP文件中?

这篇关于在Java代码之后调用Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆