how to call a method when a button is clicked in jsp?

旧巷老猫 提交于 2020-01-16 09:09:12

问题


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

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

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...


回答1:


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();"/>


来源:https://stackoverflow.com/questions/14909262/how-to-call-a-method-when-a-button-is-clicked-in-jsp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!