[英]How to call a java method from jsp by clicking a menu in html page?
I wrote a server program in java but in order to give an interface with web i want to access java method in jsp when certain menu button is clicked. 我用Java编写了一个服务器程序,但是为了提供与Web的接口,我想在单击某些菜单按钮时访问jsp中的java方法。 How can i do this?
我怎样才能做到这一点?
Using ajax (using jQuery.ajax
, you could make a request to server, In your case may be to a Servlet
which will invoke method on server that you requested 使用ajax(使用
jQuery.ajax
,您可以向服务器发出请求,在这种情况下,可能是向Servlet
发出的请求,该Servlet
将在您请求的服务器上调用方法
For example: 例如:
function callMe(){
$.ajax({
type: "POST",
url: "/someServlet",
data: { methodToInvoke: "sayHello" , data: "Abc" }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
}
at Servlet
end 在
Servlet
端
doPost(...){
String methodToCall = request.getParameter("methodToCall");
//do some stuff to determine method to call and call it like
methodService.invoke(request.getParameter("data"));
}
Also See 另请参阅
you cannot do this directly because JSP is server side and html is client side. 您不能直接执行此操作,因为JSP是服务器端,而html是客户端。 However, it can be accomplished via AJAX.
但是,可以通过AJAX完成。 http://en.wikipedia.org/wiki/Ajax_(programming )
http://en.wikipedia.org/wiki/Ajax_(编程 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.