Solved

jsp method declarations

Posted on 2003-11-21
9
416 Views
Last Modified: 2010-04-01
Is there a way of  using jsp custom tag in a jsp declaration such as:

<%!
public void pumpOutChildren(IItem currentItem)
{       
%>
<ms:bindings name="currentItem" id="boundItem">
<%=  
   boundItem.getFullName();
%>
</ms:bindings>
<%
}
%>

as this does not appear to work
0
Comment
Question by:danBosh
  • 4
  • 4
9 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 30 total points
ID: 9798965
I don't think so, as the <ms:bindings bit is outside the <%! bit, and therefore it is invalid in the generated servlet :-(

<%!
public void pumpOutChildren(IItem currentItem)
{      
%>

opens a new method in the generated Servlet, but it has no closing tags...so the JSP won't compile :-(

I hope you see what I mean...

Tim
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9798980
The answer to your question is NO!
because :
The tag needs other environment support that you don't have it in your declared method.
And you cannot mix <%! with <%.

Most of jsp processor will extract all <%! and process first, then the rest.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9799252
yeah...like I said... kinda ;-)
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9801201
sorry, only find that you have your message posted after I post mine.
points to TimYates
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 35

Expert Comment

by:TimYates
ID: 9803271
> sorry, only find that you have your message posted after I post mine.

Hee hee...no worries :-)

I'm new to the JSP TA, and it's nice to see I was right :-)

Hehehe, now to catch you up ;-)

Tim
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9806302
Tim, I have seen that your answers were/are in high quality. I have limited time to support this TA and welcome all experts to contribute. :-)
0
 

Author Comment

by:danBosh
ID: 9809208
so there is no way of doing this, ignore my syntax, i just want to achieve something like that
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9809494
Hmmmm...

You can do:

<%!
public void pumpOutChildren( IItem currentItem )
{      
    out.println( currentItem.getFullName ) ;
}
%>

Not sure that "out" will be valid though...  you might need to do:

<%!
public void pumpOutChildren( IItem currentItem, PrintWriter out )
{      
    out.println( currentItem.getFullName ) ;
}
%>

Then you can call the method from your JSP code:

<%
  pumpOutChildren( item ) ;
%>

or

<%
  pumpOutChildren( item, out ) ;
%>
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9812643
>> i just want to achieve something like that
NO, not custom tag in a jsp declaration.

But you might be able to something similar with <jsp:include>
you put you custom tag in an included jsp page, and in the main page use <jsp:include> when you need to call it.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now