mibutec
mibutec

Reputation: 2997

How to pass parameters from tag to JSP?

I have written a tag with its "logic" inside the tag class and the view inside a JSP. What I do is something like

// BodyTagSupport-Class 
pageContext.setAttribute("id", tempId);
pageContext.setAttribute("visible", visible);
pageContext.setAttribute("title", title);
pageContext.setAttribute("bodyContent", getBodyContent()
            .getString());
pageContext.include("/WEB-INF/views/include/outblender.jsp", true);

<!-- JSP -->
<div id="${id}" onclick="javascript:handleOutblending('${id}')">
  ${bodyContent}
</div>

The field ${id} inside the JSP is empty. When using pageContext.geRequest().setAttribute("id", tempId); it works fine, but that context is too big and collides with other id-fields inside m< application.

How are parameters passed from tag to jsp correctly?

Edit 22.10. Thanks to k3b for clarifying my question:

I have java code to dynamicly included jsp. How can i pass jsp-parameters from java to dynamicly loaded jsp without using session or attribute? Is there a way to do by java code?

Upvotes: 1

Views: 1937

Answers (2)

John R
John R

Reputation: 2064

Here's an example of a tag that passes 2 parameters, price and discount, to file called bill.jsp:

<jsp: include page="bill.jsp" flush="true">
    <jsp:param name="price" value="FF"/>
    <jsp:param name="discount" value="18"/>
</jsp:include>

hope it works.

Upvotes: 1

is this any of your use ??

Current.jsp

<jsp:forward page ="/DesiredPage.jsp">
<jsp: param name="param1" value="value1"/>
<jsp: param name="param2" value="value2"/>
<jsp: param name="param3" value="value3"/>
</jsp:forward>

and you can recieve this in your next page by

DesiredPage.jsp:

param1: <%= request.getParameter("param1") %>
param2: <%= request.getParameter("param2") %>
param3: <%= request.getParameter("param3") %>

Upvotes: 0

Related Questions