From: Niko S. <ni...@na...> - 2002-03-15 09:36:50
|
Ashish, > How about developing a custom tag for web apps. One that takes > jython scriplet in its body. The request, response, session etc > would be available as explicit objects. The tag could embed a > jython interpreter and execute the given code. How I wish jsp > were jython server pages! very interesting you are mentioning this idea, i was thinking in the same lines just a few days ago (and didn't come back). But through your posting i just tried it out today: and it turns out that it is possible :) (even if it is a bit more extra effort): creating just a straight forward jython class inherited from javax.servlet.jsp.tagext.TagSupport gave me a strange error message: "AttributeError: write-only attr: pageContext". Also with setting python.security.respectJavaAccessibility to false didn't help, so i had to write a Java class (derived from TagSupport) which provides an accessor method to pageContext. The Jython Custom Tag implementation has then to use this to get access to the PageContext object. ---- DemoTag.py ---- from java.io import IOException from javax.servlet.jsp import JspTagException from niko.test import JythonTagSupport class DemoTag(JythonTagSupport): def doStartTag(self): try: out = self.pageContext.getOut() out.print("Hello World from Jython Tag.") except IOException, e: raise JspTagException("Input/output error: %s" % e.toString()) # since this is an empty tag return self.SKIP_BODY ---- JythonTagSupport ---- package niko.test; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.TagSupport; public class JythonTagSupport extends TagSupport { public JythonTagSupport() { super(); } public PageContext getPageContext() { return pageContext; } } ----- Then the only two remaining steps are to define the new jython tag in your tag library descriptor file (TLD) and make sure that jython.jar is available to the classloader of your servlet container. Happy jython-custom-tag-developing :-) Niko |