在jsp中单击按钮时如何调用方法? [英] how to call a method when a button is clicked in jsp?

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

问题描述

<%!  
 public void display()  
 {  
     System.out.println("Hai");  
 }
 %>

<input type="submit" value="touch me" method="display()"/>

我有一个像上面的jsp页面.当 用户单击按钮.上面的代码不起作用.我如何不用javascript ...

I have a jsp page like above. How can i call a method when the user clicking the button.The above code is not working. How i do it without javascript...

推荐答案

您正在混淆服务器端和客户端.该代码在服务器端生成,您的用户在客户端上单击.如果要从客户端调用服务器端代码,则需要查看 ajax .
如果要在客户端执行事件,则需要使用javascript

You are confusing server side and client side. The code is generated on the server side, your user clicks on the client side. If you want to call server side code from the client side you need to look into ajax.
If you want to carry out events on the client side you need to use javascript

<script type="text/javascript>
 function alert() {
  alert("Hai");
 }
</script
<input type="submit" value="touch me" onClick="alert();"/>

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

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