单击html元素时如何从jsp调用Java方法? [英] How to call a java method from a jsp when a html element is clicked?

查看:96
本文介绍了单击html元素时如何从jsp调用Java方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,当单击某些元素(例如锚点)时,如何从jsp调用Java类方法? (无需重新加载页面)

As title says, how do I call a java class method from a jsp, when certain element is clicked (by example an anchor)? (Without reloading the page)

如果可以做到,我如何传递方法,调用该方法的页面的html代码的某些部分?

If this can be done, how I pass the method, some part of the html code of the page that invokes it?

我通过Jboss AS使用jsp,servlet,javascript,struts2和java.

Im using jsp, servlets, javascript, struts2 and java, over Jboss AS.

推荐答案

您想要做的是,当单击该元素时,让javascript触发AJAX请求.该AJAX请求将转到服务器,该服务器随后可以调用您想要的任何Java代码.

What you want to do is have javascript fire off an AJAX request when the said element is clicked. This AJAX request will go to the server which can then invoke any java code you want.

现在,您可以自己构建所有这些,也可以使用许多现成的解决方案之一.我建议为JSP Ajax标记库使用Googling.像这样的 http://ajaxtags.sourceforge.net/.

Now you can build this all yourself or you could use one of the many off the shelf solutions. I would recommend Googling around for a JSP Ajax tag library. Like this one http://ajaxtags.sourceforge.net/ .

这篇关于单击html元素时如何从jsp调用Java方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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