9

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?

Neha Gupta
  • 987
  • 5
  • 16
  • 35

2 Answers2

23

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}
Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56
14

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>
Developer Desk
  • 2,294
  • 8
  • 36
  • 77