To complete your deployment, copy the compiled tag library and the
taglib.tld into the
To test you new tag library, you need to modify the welcome.jsp
page, replacing the Welcome message with a reference to the
<onjava:hello /> tag. You need to also add a taglib
directive referencing the
taglib.tld to the
welcome.jsp file. The modified JSP is in Listing 7.
Listing 7 Modified
<%@ taglib uri="/onjava" prefix="onjava" %>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<b><onjava:hello /> : <%= request.getAttribute("USER") %></b>
Now open the
login.jsp page as described previously
and run through the demo again. This time instead of Welcome:
Bob, you should see the message Hello: Bob.
Creating and Deploying a WAR File
When your web application is ready for deployment, you need to
package it for distribution. As we discussed previously in Java Web Applications,
web applications are packaged in WAR files. The steps required to
/onjava web application and deploy it are
Change to the root directory of your web application. In this case the root directory would be
Archive the web application:
jar cvf onjava.war .
Copy the resulting WAR file,
onjava.war, to the
If you're deploying this WAR file to the Tomcat installation that you were developing in, then you will need to back up your development directory and remove it from the
Add a new Context entry to the
/TOMCAT_HOME/conf/server.xmlfile, referencing the onjava web application.
That's it. Your application should now be deployed and running. If
it isn't, check your entry in the
TOMCAT_HOME/conf/server.xml file to ensure that you have
set the appropriate values.
Now that you know how to create and deploy a web applications,
we'll examine the relationship of the web application and
ServletContext in a future article.
Read more Using Tomcat columns.
Return to ONJava.com.