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?

2 Answers 2

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}
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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.