如何从java类到javascript获取变量数据?
这是我的java类方法,我想在jsp页面的变量如何从java类到javascript获取变量数据?,javascript,java,jsp,Javascript,Java,Jsp,这是我的java类方法,我想在jsp页面的变量am或javascript函数中获取数据?您可以这样使用: public String getVatNetAmount() { String expensetype = getRequest().getParameter("type"); String localAmount = getRequest().getParameter("amount"); Double localamt = Dou
am
或javascript函数中获取数据?您可以这样使用:
public String getVatNetAmount()
{
String expensetype = getRequest().getParameter("type");
String localAmount = getRequest().getParameter("amount");
Double localamt = Double.parseDouble(localAmount);
Double netAmount;
netAmount = getExpensesTypeManager().getVatNetAmount(expensetype,localAmount);
am = (float) ((localamt * netAmount)/100);
// getRequest().setAttribute("NetAmount", am);
return INPUT;
}
var值=”;
您可以这样使用:
public String getVatNetAmount()
{
String expensetype = getRequest().getParameter("type");
String localAmount = getRequest().getParameter("amount");
Double localamt = Double.parseDouble(localAmount);
Double netAmount;
netAmount = getExpensesTypeManager().getVatNetAmount(expensetype,localAmount);
am = (float) ((localamt * netAmount)/100);
// getRequest().setAttribute("NetAmount", am);
return INPUT;
}
var值=”;
在SpringMVC中,您可以使用
<%
String var="sth";
%>
<script>
var value = "<%=var%>";
</script>
现在,我们来看看javascript。(使用JSTL库)
var data='${keyForJsp}';
在SpringMVC中,您可以使用
<%
String var="sth";
%>
<script>
var value = "<%=var%>";
</script>
现在,我们来看看javascript。(使用JSTL库)
var data='${keyForJsp}';
您可以通过多种方式完成。最简单的方法是将变量设置为Session属性,并在jspor中访问它,将其存储在模型中,然后在jsp中使用此代码获取它,这对您的问题是无用的。您当前用于将数据放入页面的代码是什么?(如果你不知道从哪里开始,先在谷歌上搜索一下)你可以用很多方法。最简单的方法是将变量设置为Session属性,并在jspor中访问它,将其存储在模型中,然后在jsp中使用此代码获取它,这对您的问题是无用的。您当前用于将数据放入页面的代码是什么?(如果你不知道从哪里开始,先进行谷歌搜索)是的,没错@ThiloYup,没错@Thilo