weixin_33725807 2019-05-30 06:55 采纳率: 0%
浏览 80

AJAX调用Java方法

There are many similar questions but I am not clear about one thing as mentioned below-

I have ajax call

var url = '/test/testjsp.do?param1=' + xyz;    
$.ajax({
                    type:'GET',
                    dataType:'html',
                    url:url,
                    success:function (data) {
                        alert("Success");
                    }
                });

which is calling an JSP page and in that file, I am calling method from SM class

<%@ page import="com.testAjax.SM" %>

<%

    if (null != request.getParameter("
        SM.randomMethod(request.getParameter("param1"));
    }
%>

So my question is ,

I there any alternative method where I don't have to create extra Jsp file and call java method directly from Ajax call

Please help and Advise

  • 写回答

1条回答 默认 最新

  • weixin_33681778 2019-05-30 07:33
    关注

    As javascript is a client side script, it cannot invoke java methods directly which resides on the server.

    To do that you have to create a web service or jsp like you did.

    But I have seen vaadin gives option to call java code from javascript without writing a service or jsp. I dont know how it will help you.

    https://vaadin.com/tutorials/calling-java-from-javascript

    There are some concept like java adaptors and javavm to combine javascript and java try them to find it suits your need.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器