I want to call a java function named setrowNumber(1), that sets the row number to a static int variable. And I want this function to be called when the link is clicked but that does'nt seem to happen.
The problem is in that part only because when i try to set the value manually it works fine.
<a href="single.jsp" onclick= "<%conc.setrowNumber(1);%>" > <i class="glyphicon glyphicon-menu-right icon" ></i></a>
I am making java web application on struts framework, using net beans and wamp server.
If I use javascript function and use it with onclick event then how can I pass value to java function.e.g
<a href="single.jsp" onclick= "myFunc(1)" > <i class="glyphicon glyphicon-menu-right icon" ></i></a>
<script type="text/javascript">
function myFunc (int a) {
<% conc.setrowNumber(a); %> //how to write java function and pass value here because a is not known var here.
}
</script>
答案 0 :(得分:1)
试试这个。
<s:url id="yourId" action="yourActionName"></s:url>
<s:a href="%{#yourId}"><img src="<s:url value="/images/submit.png" /> </s:a>
在jsp上建立一个链接,通过该URL可以调用Action。
答案 1 :(得分:0)
尝试以下代码
<a href="#" onclick= "<% conc.setrowNumber(1); %> return false;" > <i class="glyphicon glyphicon-menu-right icon" ></i></a>
答案 2 :(得分:0)
通常使用JavaScript中的AJAX调用,在异步模式下完成:您发送到服务器,并可能注册一个JavaScript函数来回调。网络搜索会给出示例。在你的情况下。一个链接,您可以使用参数为href位置分配一个URL。
this.href.url = "single.jsp?a=" + a;
答案 3 :(得分:0)
在你的jsp中包含已经具有此功能的类
<%@page import="package.subPackage.TheClassName"%>
在scriptlet标记中,您可以调用该方法。
<%
TheClassName theClassInstance = new TheClassName();
theClassInstance.doSomething();
%>
如果是静态方法,则不需要创建实例。