Opened 16 years ago

Closed 16 years ago

#989 closed enhancement (fixed)

Add support for using extension classes in custom JSP pages

Reported by: Nicklas Nordborg Owned by: Nicklas Nordborg
Priority: minor Milestone: BASE 2.7
Component: web Version:
Keywords: Cc:

Description

An extensions that uses custom JSP pages are currently limited to use only classes from JAR file installed in WEB-INF/lib. It can't use classes from it's own JAR file. The reason is simply that Tomcat doesn't know about the extension JAR files in WEB-INF/extensions. The current workaround for extensions that need custom classes is to place a second JAR file in WEB-INF/lib that contains those classes. The drawback is that this requires a restart.

I have tested a few ideas with varying results. There is one that I got to work.

  • We have to remap the servlet for *.jsp. We can use the same servlet as Tomcat uses, but we have to specify another compiler. This can be done in web.xml.
  • The compiler should override the default compiler and needs to check the request path. If it is in the /extensions directory the compiler must extract the JARNAME from the path, and create a classloader for it. Then, it replaces the classloader Tomcat's compiler with the JARFILE classloader.
  • The drawback with this solution is that the class we specify as a compiler must be in a JAR that is located in Tomcat's internal lib-directory. This also means that the compiler code doesn't have direct access to the BASE core classes. Fortunately it has access to the classloader Tomcat uses for BASE and can use reflection to access the BASE core classes. The code is not pretty though.

Note! Since this solution requires special installation of JAR files into Tomcats internal directories, I think this should be optional. It only needs to be installed if an extension requires it. I am also a bit unsure of compatibility with future versions of Tomcat. The JSP compiler is not part of any specification so we are really hooking into code that is specific for Tomcat. This solution will probably not work for other servlet containers.

Change History (5)

comment:1 by Nicklas Nordborg, 16 years ago

Owner: changed from everyone to Nicklas Nordborg
Status: newassigned

comment:2 by Nicklas Nordborg, 16 years ago

(In [4222]) References #989: Add support for using extension classes in custom JSP pages

This is now implemented. Need to write documentation also.

comment:3 by Nicklas Nordborg, 16 years ago

(In [4223]) References #989: Add support for using extension classes in custom JSP pages

Updated documentation with information about the X-JSP compiler.

comment:4 by Nicklas Nordborg, 16 years ago

(In [4225]) References #989: Add support for using extension classes in custom JSP pages

Also map *.xjsp through character encoding filter.

comment:5 by Nicklas Nordborg, 16 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.