How to display a variable value in JSP file

2019-05-01 15:47发布

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

index.html(line 5)-

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

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 scriplets
2条回答
等我变得足够好
2楼-- · 2019-05-01 16:03

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

some thing like this,

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

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}
查看更多
时光不老,我们不散
3楼-- · 2019-05-01 16:05

I think this what you are looking for.....

page1.html...

 <a href="page2.jsp?id=5">Go</a>

page2.html

    <% String id = request.getParameter("id"); %>
    <div class="marginTable" data-pubid="<%=id%>" data-count="5"></div>
查看更多
登录 后发表回答