Ajax preparation filter ver. 1.2


This is a Java servlet filter (as per Servlet API 2.3). toAjaxFilter lets you present the response in XML format. Filter lets you reuse the existing content in your Ajax applications for example. Filter intercepts the response and presents output as XML CDATA content, so your JavaScript XML parser will be able to extract HTML code wrapped by XML tags.

For example, suppose your Ajax application needs to obtain HTML content prepared by JSP file and use this content for the updating some div block (via innerHtml property).

In this case the requested JSP file must present own data in XML format. So without the converting it to XHTML you can simply proceed it through this filter.

How to use it:

a) download toajaxflt.jar and save it in WEB-INF/lib

b) describe this filter in web.xml
 


<filter>
  <filter-name>toAjaxFilter</filter-name>
  <filter-class>com.cj.ajax.toAjaxFilter</filter-class>
</filter>

c) describe a mapping for this filter in web.xml. For example, let we do this for all files in /response sub-directory:
 


<filter-mapping>
  <filter-name>toAjaxFilter</filter-name>
  <url-pattern>/response/*</url-pattern>
</filter-mapping>

And now when you request any .jsp file from the above mentioned directory: http://your_host/response/some_file.jsp toAjaxFilter will return it as XML data.

You can provide an initial parameter tagName describes a name for XML tag. By default it will be text. E.g.:
 


<filter>
  <filter-name>toAjaxFilter</filter-name>
  <filter-class>com.cj.ajax.toAjaxFilter</filter-class>
  <init-param>
    <param-name>tagName</param-name>
    <param-value>mycode</param-value>
  </init-param>
</filter>

See also Ajax preparation taglib in Coldtags suite for the practical examples.
 

    For downloading:   toajaxflt.jar
 

 ©  Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: