如何在JSP文件中显示变量值 [英] How to display a variable value in JSP file

查看:646
本文介绍了如何在JSP文件中显示变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的代码中显示名为"id"的变量的值.代码是-

I want to display the value of variable named "id" in my code. The code is -

index.html(第5行)-

index.html(line 5)-

 <div class="marginTable" data-pubid="<%=id%>" data-count="5">

但是每当我执行它时,它就会抛出错误 jsp文件:/index.html中的第5行出现错误 id无法解析为变量.如何摆脱困境?

But whenever i am executing it, it is throwing error An error occurred at line: 5 in the jsp file: /index.html id cannot be resolved to a variable. How to get out of this?

推荐答案

要在jsp中显示服务器端变量,可以使用隐式对象 out.

To display the server side variables in jsp , you can use implicit object out.

类似这样的东西

<div class="marginTable"  data-count="5">
  <%=id%>
</div>

但是使用scriptlet被认为是不好的做法.因此您可以使用EL以获得更多信息,请参见如何避免JSP文件?

But using scriptlets is considered as the bad practice . so you may use EL for more info see this How to avoid Java code in JSP files? as,

${id}

这篇关于如何在JSP文件中显示变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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