Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP Tag Library and Scriptlets Question (Sort of)

Status
Not open for further replies.

tommyc7

Programmer
Feb 3, 2007
33
US
I have just read this article and am working on a web project using it:



There's only one thing that either I'm missing or it doesn't say that I need to do.

If I set up a template tag, how can I use the content data in a scriptlet?

For example, say this is test.jsp:

Code:
<%@ taglib uri='/WEB-INF/template/template.tld' prefix='template' %>

<template:insert template='/template.jsp'>
  <template:put name='test' content='500' direct='true'/>
</template:insert>

If know I can do this in template.jsp:

Code:
<h1>Test = <template:get name='test'/></h1>

To display:

Test = 500


However, what I need to do is something like the following (and I know I have the types wrong, this is just psuedo-code):

Code:
<%
int i = <template:get name='test'/> * 2;
%>
<h1>Test * 2 = <%= i ></h1>

The compiler won't now how to handle that, though, right? Is there another way to do that?


Thanks,
Tom
 
I figured it out... At least one way... You need to do this:

Code:
<%
Stack stack = (Stack)pageContext.getAttribute("template-stack", PageContext.REQUEST_SCOPE);

if(stack == null)
{
	throw new JspException("test.jsp: NO STACK");
}

Hashtable params = (Hashtable)stack.peek();

if(params == null)
{
	throw new JspException("test.jsp: NO HASHTABLE");
}

int test = 0;

PageParameter testParam =  (PageParameter)params.get("test");

if(testParam == null ||!testParam.isDirect())
{
	test = 0;
}
else
{
	test= Integer.parseInt(testParam.getContent());
}

%>

<h1>Test * 2 = <%= test %></h1>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top