[英]Alert box doesn't display anything
The JSP is: JSP是:
<input type="submit" value="GENERATE TICKET" class="button" name="generate" onclick="myFunction()">
<script>
function myFunction() {
alert(
<%SelectCustomer sc = new SelectCustomer();
System.out.println(sc.getCash());%>
);
}
</script>
The java class is: Java类是:
public class SelectCustomer
{
public int getCash() throws SQlException
{
return 12;
}
}
The alert box pops but is blank. 警报框弹出,但为空白。 What is the reason?
是什么原因? How to print 12 in the alert box?
如何在警告框中打印12?
Try using <%= %>
instead of <% %>
. 尝试使用
<%= %>
而不是<% %>
。
Also make sure you are using quotes inside of your alert function call. 还要确保在警报函数调用中使用引号。
try this code add an input hidden were you put the wanted value 尝试这段代码添加一个隐藏的输入,如果您想要的值
<input type='hidden' name='' id='data' value=' <%= VALUE-HERE %>' />
Then JS : 然后JS:
var content =document.getElementById('data').getAttribute('value');
alert(content);
Please try with this script: 请尝试使用以下脚本:
<script>
function myFunction() {
<% Windowlogin sc = new Windowlogin();%>
alert(<%=sc.getCash()%>);
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.