Home | Exchange | FAQ | Software & Standards
In
JSP this is best done using Java code:
<ahref="<%=request.getContextPath()
%>/index.html">Home page</a>
<a href="<jsp:getProperty
name="request"
property="contextPath"/>/index.html">HomePage</a>
Using a template engine there's no Java code and no ugly syntax.
Here's the same command written in WebMacro:
<a href="$Request.ContextPath;/index.html">Home
page</a>
In WebMacro, ContextPath
is seen as a property of the $Request variable, accessed using a
Perl-like syntax. Other template engines use other syntax
styles.
<% Cookie c =
new Cookie ("colorscheme", "blue");
response.addCookie;%>
In
WebMacro there's no Java code:
#set
$Cookie.colorscheme = "blue"
<%
String colorscheme = ServletUtils.getCookie (request, "colorscheme");%>
In WebMacro there's no need for a utility class and it's always:
$Cookie.colorscheme.Value
<%
String title = "The Page Title"; %>
<%@ include file="/header.jsp" %>
Your content here
<%@ include file="/footer.jsp" %>
Page creators must not forget the semicolon in the first line and
must make sure to declare title as a Java String. Plus, the /header.jsp
and /footer.jsp must be made publicly accessible
somewhere under the document root even though they aren't full pages
themselves.
#set
$title = "The Page Title"
#parse "header.wm"
Your content here
#parse "footer.wm"
|
[ Previous Page] |
About the Author
Jason
Hunter works as the Chief Technology Officer of K&A Software,
where he specializes in Java training and consulting. He is
author of Java Servlet Programming (O'Reilly) and publisher
of the Web site http://www.servlets.com.
He belongs to the working group responsible for Java Servlet
API development and has made significant contributions to
the Servlet API and reference implementation. He also writes
columns for JavaWorld and speaks at conferences such as JavaOne,
Software Development, Web Design & Development, and the
SIGS JavaExpo.
Jason graduated summa cum laude from Willamette
University (Salem, Oregon) in 1995 with a degree in Computer Science.
After graduation, he worked at Silicon Graphics in Mountain View, CA, for
several years, where he was responsible for developing (and breaking) all
sorts of Web technologies.
TechMetrix Research is a technically focused analyst firm focused on e-business application development needs. Based in Boston, Mass., the firm publishes comparison reports and product reviews designed to aid enterprises with decision making and to keep pace with the fast-moving e-business market.
TechMetrix is a U.S.-based subsidiary of SQLI, a European company that offers on-site development services to international organizations. SQLI specializes in e-business project development.