0

JSP Newbie:

I have a piece of code that works perfectly within the <% %> brackets but I need it to work within the <%! %> brackets.

Here is the code:
------------------------

com.newatlanta.cfc.CFCProxy myCFC = new com.newatlanta.cfc.CFCProxy("xmpp", request, response);
		
		    String jsonMsgData = "A test message";
		    Object[] myArgs = {jsonMsgData};
		
		    java.util.Map map = (java.util.Map)myCFC.invoke("OnAvailabilityChange", myArgs);

-------------------------

I am working with XMPP / Jabber using Smack and I need for this piece of code to be triggered when there is a change in user presence. I already have the trigger code working within the <%! %> brackets and just need to plug this piece in it to be executed. Right now, what I have the trigger code doing is sending me an IM of the user presence. I want to replace the "IM message code" with the above code to be executed.

Obviously the code above is some sort of servlet and I know it works for sure -BUT ONLY- within the <% %> brackets as mentioned previously. Is there a way I can call that piece of code a as a function like doCFCProxy(arg1, arg2...); into the trigger code (that is surrpunded by <%! %>)?

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by ~s.o.s~
1

Anything placed in the JSP between the <%! %> tags [jsp declaration tag] is placed outside the service() method but inside the auto-generated servlet class. You can of course create a method containing the given piece of code, which can be invoked from within the code placed inside the <% %> [scriptlet tags]

The bottom line is that anything placed in the JSP declaration section forms part of the auto-generated servlet [and is *not* executed] whereas anything placed between the JSP scriptlet tags is executed for every request received by that JSP. In your case, you might want to declare a method in the declaration section and invoke the same from a scriptlet.
.

<%!
private static void invokeSomething() {
    // your stuff here
}
%>

<%
invokeSomething();
%>

Oh, and in case you didn't know, placing logic in JSP's and using scriptlets is bad and has been deprecated since times unknown.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.