简体   繁体   中英

How can i pass parameters in pageContext include

In my application I am trying to do a pageContext include in a custom tag java file. I am going to include a jsp file.

Can I pass any parameters to the jsp file which would be scoped only to the file(like params passed in jsp:include)?

I am aware that I can set it as an attribute in the request and use it in the jsp, however I don't think this is the best solution as I do not want it to persist in the request. Besides, the jsp file may in turn use the same tag again, which would override this attribute, and the rest of the jsp would have the wrong attribute.

Here is the code for that:

request.setAttribute("myVariable", this.viewletId);

pageContext.include(viewletLayout);

Is there a way to pass it to just the jsp in its scope(Like jsp:include)?

Look here to get the solution that hinted me to what worked for me:

    <% 
        if ("layout1".equalsIgnoreCase(viewletLayout)){
            %><%@include file="layout1.jsp"%><%
        } else if ("layout2".equalsIgnoreCase(viewletLayout)){
            %><%@include file="layout2.jsp"%><%
        }
    %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM