Monday, March 23, 2009

What's the Deal with java tags in JSP and JHTML Pages?

Note: The information in this article is for Dynamo 5.1 only

Example Code

Let's look at an example. The server code below uses both and <% %>tags, we can save the same page with both a .jsp and .jhtml extension and get different results

Java Server Page
iJavaTag++;

As a JHTML Page you can effectively use the jsp tags in a JHTML page for java code, the result of firing up our java_server_page.jhtml page is as follows:

Java Server Page

Test JSP tag: 1

Test JSP < % % > tag: 1
We see that both the <% %>and tag delimited code is part of the page servlet as a JSP page you cannot effectively use the jhtml tags in a JSP page for java code, the result of firing up our java_server_page.jsp page is as follows:

Java Server Page

iJavaTag++;

Test JSP tag: 0

Test JSP < % % > tag: 1
We see that the tags are not processed on the server and are passed down untouched to the client. This is because these tags are not a part of the JSP specification.

Summary

Files ending in .JHTML are processed with the JHTML tags enabled as a superset of the JSP standard.

This means:
You can save JSP pages as .jhtml files and they will work fine
JHTML tags are not processed on the server for .jsp files

No comments:

Post a Comment