My doubt is: How do I obtain a reference to a variable in the JSP page, which I have defined in my tag. eg: I have a tag of the following fromat - <mytag:tmvalue name="TM" value="value1" id="test" output="true" /> which outputs the value inside the TreeMap TM that is set in pageContext and also stores its value inside the attribute 'test'. some code to explain further - In my JSP I have done the following - <% TreeMap tm = new TreeMap(); tm.put("val1", "Hello"); tm.put("val2", "Hello World"); pageContext.getAttribute("TM", tm); %> <mytag:tmvalue name="TM" value="val1" id="test" output="true" /> My question is how to access 'test' variable directly in JSP. Something like this - <%=test%> Is it possible and how? I've tried to give pageContext.setAttribute("test", value); in my doStartTag() method of my TagHandler class but I'm still not getting it. Error comes up as "test" is undefined. Please help me to know how variables are stored in JSP and relationship with the pageContext object. regards, Sam.
Joined: Aug 13, 2001
Hi, If you want to access the variables and print on the page them using the taglib, I suggest you have a look at the code of JSTL. In JSTL there is a custom tag 'C'. You can use <C:0UT> to print the var. on the page. Or better way if you can use the JSTL for all your needs it will solve most og your display problems. Let me know if I have understood your problem correctly or you need something else. -Kaustubh [ September 24, 2003: Message edited by: Kaustubh Patil ]
Kaustubh. Mumbai, India.
Joined: Jun 05, 2003
Hi, JSTL is a good option. I hadn't thouight about it. Guess I'll have to spend some time in learning the tags. But the question is how are variables passed between tags and JSP if I want to pass them? regards, Sam.