%@ page import="java.io.File" %> <%@ page import="java.util.Date" %> <%@ taglib uri="gnat" prefix="gnat" %> <%-- Use the Servlet 2.2+ temporary working directory to demo some file stuff. Makes it easier because the user doesn't have to configure anything and I don't have to worry about file system and user permissions for the demo. See section 3.7 of Servlet 2.3 spec for description of this attribute. --%> <%! File tempdir = null; %> <% tempdir = (File)application.getAttribute("javax.servlet.context.tempdir"); %>
The Echo tag writes a message to the JSP output stream. The Echo tag can also take body content instead of a message attribute. The file and append attributes are used to write messages to a file.
example 1 - echo a simple message to JSPWriter out.
<gnat:echo message=""/> :
example 2 - echo and append to logfile
<gnat:echo message="<%= messageString %>" append="true" file="<%= echoLog %>" />
example 3 - echo to logfile, do not append
<% String echoLog2 = tempdir+"/echoNoAppendLog.txt"; %><gnat:echo message="<%= messageString %>" file="<%= echoLog2 %>" />
example 4 - echo to JSP output, no attributes
<gnat:echo>
Hello, here is a message! (and a dynamic date: <%= time %>).
</gnat:echo>