Installing the JSTL Distribution

Making t he driver m ore globally accessible also is useful if you t hink it likely t hat at som e point youll elect t o use JDBC- based session m anagem ent or realm aut hent icat ion. Those act ivit ies are handled by Tom cat it self above t he applicat ion level, so Tom cat needs access t o t he driver t o carry t hem out . Heres an exam ple inst allat ion procedure for Unix, assum ing t hat t he MySQL Connect or J driver and Tom cat are locat ed at src Java m ysql- connect or- j ava- bin.j ar and usr local j akart a- t om cat . The com m and t o inst all t he driver would look like t his: cp srcJavamysql-connector-java-bin.jar usrlocaljakarta- tomcatcommonlib For Windows, if t he com ponent s are inst alled at D: \ m ysql- connect or-j ava-bin.j ar and D: \ j akart a- t om cat , t he com m and looks like t his: C:\ copy D:\mysql-connector-java-bin.jar D:\jakarta-tomcat\common\lib Aft er inst alling t he driver, rest art Tom cat and t hen request t he following mcb applicat ion page t o verify t hat Tom cat can find t he JDBC driver properly: ht t p: t om cat .snake.net : 8080 m cb j dbc_t est .j sp You m ay need t o edit j dbc_t est .j sp first t o change t he connect ion param et ers.

16.4.6 Installing the JSTL Distribution

Most of t he script s t hat are part of t he mcb sam ple applicat ion use JSTL, so it s necessary t o inst all it or t hose script s wont work. To inst all a t ag library int o an applicat ion cont ext , copy t he librarys files int o t he proper locat ions under t he applicat ions WEB- I NF direct ory. Generally, t his m eans inst alling at least one JAR file and a t ag library descript or TLD file, and adding som e t ag library inform at ion t o t he applicat ions web.xm l file. JSTL act ually consist s of several t ag set s, so t here are t here are several JAR files and TLD files. The following inst ruct ions describe how t o inst all JSTL for use wit h t he mcb applicat ion: • Make sure t hat t he m cb.war file has been unpacked t o creat e t he mcb applicat ion direct ory hierarchy under t he Tom cat webapps direct ory. See Recipe 16.4.416.4.4 . This is necessary because t he JSTL files m ust be inst alled under t he m cb WEB- I NF direct ory, which will not exist unt il m cb.war has been unpacked. • Get t he JSTL dist ribut ion from t he Jakart a Proj ect web sit e. Go t o t he Jakart a Taglibs proj ect page, which is accessible at t his URL: ht t p: j akart a.apache.org t aglibs Follow t he St andard Taglib link t o get t o t he JSTL inform at ion page; t he lat t er has a Downloads sect ion from which you can get t he binary JSTL dist ribut ion. • Unpack t he JSTL dist ribut ion int o som e convenient locat ion, preferably out side of t he Tom cat hierarchy. The com m ands t o do t his are sim ilar t o t hose used t o unpack Tom cat it self see Recipe . For exam ple, t o unpack a ZI P form at dist ribut ion, use t he following com m and, adj ust ing t he filenam e as necessary: jar xf jakarta-taglibs-standard.zip • Unpacking t he dist ribut ion will creat e a direct ory cont aining several files. Copy t he JAR files j st l.j ar, st andard.j ar, and so fort h t o t he m cb WEB-I NF lib direct ory. These files cont ain t he class libraries t hat im plem ent t he JSTL t ag act ions. Copy t he t ag library descript or files c.t ld, sql.t ld, and so fort h t o t he m cb WEB-I NF direct ory. These files define t he int erface for t he act ions im plem ent ed by t he classes in t he JAR files. • The m cb WEB- I NF direct ory cont ains a file nam ed web.xm l t hat is t he web applicat ion deploym ent descript or file a fancy nam e for configurat ion file . Modify web.xm l t o add taglib ent ries for each of t he JSTL TLD files. The ent ries will look som et hing like t his: • taglib • taglib-urihttp:java.sun.comjstlcoretaglib-uri • taglib-locationWEB-INFc.tldtaglib-location • taglib • taglib • taglib-urihttp:java.sun.comjstlsqltaglib-uri • taglib-locationWEB-INFsql.tldtaglib-location taglib Each taglib ent ry cont ains a taglib-uri elem ent t hat specifies t he sym bolic nam e by which mcb JSP pages will refer t o t he corresponding TLD file, and a taglib-location elem ent t hat indicat es t he locat ion of t he TLD file under t he mcb applicat ion direct ory. Youll find t hat web.xm l as dist ribut ed already cont ains t hese ent ries. However, you should t ake a look at t hem t o m ake sure t hey m at ch t he filenam es of t he TLD files t hat you j ust inst alled in t he previous st ep. • The m cb WEB- I NF direct ory also cont ains a file nam ed j st l- m cb- set up.inc. This file is not part of JSTL it self, but it cont ains a JSTL sql:setDataSource t ag t hat is used by m any of t he mcb JSP pages t o set up a dat a source for connect ing t o t he cookbook dat abase. The file looks like t his: • sql:setDataSource var=conn • driver=com.mysql.jdbc.Driver url=jdbc:mysql:localhostcookbook user=cbuser password=cbpass Edit t he driver , url , user , and password t ag at t ribut es as necessary t o change t he connect ion param et ers t o t hose t hat you use for accessing t he cookbook dat abase. Do not change t he var at t r ibut e. • The JSTL dist ribut ion also includes WAR files cont aining docum ent at ion and exam ples st andard-doc.war and st andard-exam ples.war . I f you wish t o inst all t hese, copy t hem int o Tom cat s webapps direct ory. You probably should inst all t he docum ent at ion so t hat you can access it locally from your own server. I t s useful t o inst all t he exam ples as well, because t hey provide helpful dem onst rat ions showing how t o use JSTL t ags in JSP pages. • Rest art Tom cat so t hat it not ices t he changes youve j ust m ade t o t he mcb applicat ion and so t hat it unpacks t he WAR files cont aining t he JSTL docum ent at ion and exam ples. I f Tom cat doesnt unpack WAR files for you aut om at ically, see t he sidebar Unpacking a WAR File Manually . Aft er inst alling JSTL, rest art Tom cat and request t he following mcb applicat ion page t o verify t hat Tom cat can find t he JSTL t ags properly: ht t p: t om cat .snake.net : 8080 m cb j st l_t est .j sp

16.4.7 Writing JSP Pages with JSTL