28
NetBeans IDE Field Guide Copyright  © 2005 Sun Microsystems, Inc. All rights reserved. Table of Contents Developing We Applic!tions...........................................................................................................2 "epresent!tion o# We Applic!tions in the ID$...........................................................................% &ro'ect (ie) o# We Applic!tions...........................................................................................% *ile (ie) o# We Applic!tions.................................................................................................%  Adding *i les !nd +ir !ries to our We Applic!tion. ................................................................... 5 Cre!ting We &!ges !nd -ther &ulic *iles.......................................................................... Cre!ting Cl!sses, Servlets, !nd -ther &riv!te *iles...............................................................  Adding $/ tern!l "esou rces to our &r o'ect.... ........................................................................  Adding 1!gs !nd 1!g +ir!ri es............................................................................................... $diting !nd "e#!ctoring We Applic!tion *iles............................................................................ Completing 1!gs...................................................................................................................30 $/p!nding Arevi!tions #or 4S& *iles.................................................................................33 M!nu!lly $diting the Deployment Descriptor........................................................................32 "e#!ctorin g We Components .............................................................................................. 3% Deploying ! We Applic!tion.....................................................................................................3 Customi6ing Contents o# the WA" *ile......................................................................... .......3 7ndeploying ! We Applic!tion............................................................................................35 "edeploying ! We Applic!tion............................................................................................35 Cre!ting ! WA" *ile.............................................................................................................35 Deploying to ! Di##erent 1omc!t Server................................................................................35 1esting !nd Deugging our We Applic!ti on...................................................................... ....38 Chec9ing *or 4S& $rrors......................................................................................................3 (ie)ing ! 4S& *ile:s Servlet..................................................................................................3 (ie)ing ! *ile in ! We ;ro)ser..........................................................................................3 &!ssing "e<uest &!r!meters to ! We Applic!tion.............................................................3 Deugging 4S& !nd 1!g *iles..............................................................................................3 Cre!ting !nd Deploying Applets.................................................................................................3 Cre!ting !n Applet................................................................................................................3 "unning !nd Deugging !n Applet in the Applet (ie)er......................................................3 "unning !n Applet in ! We ;ro)ser...................................................................................3 &!c9!ging !n Applet into ! 4A" *ile.....................................................................................20 &!c9!ging !n Applet into ! WA" *ile...................................................................................20 Setting Applet &ermissions...................................................................................................20 Ch!nging the ID$:s De#!ult We ;ro)ser.................................................................................23 Monitoring =11& 1r!ns!ctions..................................................................................................23 Setting 7p the =11& Monitor................................................................................................22 Setting 7p the =11& Monitor *or Servers St!rted -utside o# the ID$.................................22  An!ly6 ing the Collected D!t! ................................................................................................2 "epl!ying =11& "e<uests...................................................................................................2 >et;e!ns ID$ *ield ?uide, Developing We Applic!ti ons, 3

WebApps Tomcat

Embed Size (px)

Citation preview

Page 1: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 1/28

NetBeans IDE Field GuideCopyright © 2005 Sun Microsystems, Inc. All rights reserved.

Table of Contents

Developing We Applic!tions...........................................................................................................2"epresent!tion o# We Applic!tions in the ID$...........................................................................%

&ro'ect (ie) o# We Applic!tions...........................................................................................%*ile (ie) o# We Applic!tions.................................................................................................%

 Adding *iles !nd +ir!ries to our We Applic!tion....................................................................5Cre!ting We &!ges !nd -ther &ulic *iles..........................................................................Cre!ting Cl!sses, Servlets, !nd -ther &riv!te *iles...............................................................

 Adding $/tern!l "esources to our &ro'ect............................................................................

 Adding 1!gs !nd 1!g +ir!ries...............................................................................................$diting !nd "e#!ctoring We Applic!tion *iles............................................................................Completing 1!gs...................................................................................................................30$/p!nding Arevi!tions #or 4S& *iles.................................................................................33M!nu!lly $diting the Deployment Descriptor........................................................................32"e#!ctoring We Components..............................................................................................3%

Deploying ! We Applic!tion.....................................................................................................3Customi6ing Contents o# the WA" *ile................................................................................37ndeploying ! We Applic!tion............................................................................................35"edeploying ! We Applic!tion............................................................................................35Cre!ting ! WA" *ile.............................................................................................................35Deploying to ! Di##erent 1omc!t Server................................................................................35

1esting !nd Deugging our We Applic!tion..........................................................................38Chec9ing *or 4S& $rrors......................................................................................................3

(ie)ing ! 4S& *ile:s Servlet..................................................................................................3(ie)ing ! *ile in ! We ;ro)ser..........................................................................................3&!ssing "e<uest &!r!meters to ! We Applic!tion.............................................................3Deugging 4S& !nd 1!g *iles..............................................................................................3

Cre!ting !nd Deploying Applets.................................................................................................3Cre!ting !n Applet................................................................................................................3"unning !nd Deugging !n Applet in the Applet (ie)er......................................................3"unning !n Applet in ! We ;ro)ser...................................................................................3&!c9!ging !n Applet into ! 4A" *ile.....................................................................................20&!c9!ging !n Applet into ! WA" *ile...................................................................................20Setting Applet &ermissions...................................................................................................20

Ch!nging the ID$:s De#!ult We ;ro)ser.................................................................................23Monitoring =11& 1r!ns!ctions..................................................................................................23

Setting 7p the =11& Monitor................................................................................................22

Setting 7p the =11& Monitor *or Servers St!rted -utside o# the ID$.................................22 An!ly6ing the Collected D!t!................................................................................................2"epl!ying =11& "e<uests...................................................................................................2

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 3

Page 2: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 2/28

Page 3: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 3/28

Representation of Web Applications in the IDE 

Web applications are based on a somewhat intricate architecture where the development%timelayout of files differs from that of a built application. The IDE helps you manage this process by#

• $roviding a development%time oriented view of your pro"ect in the $ro"ectswindow. This view gives you easy access to your sources and informationabout your classpath but hides build results and pro"ect metadata. $erhapsmore importantly, wor!ing in the $ro"ects window ensures that none of thefiles you create will be inadvertently deleted when you run the leancommand on your pro"ect (as could happen, for e-ample, if you wor!eddirectly in the WEB-INF folder of a built application).

• $roviding a file%oriented view of your pro"ect in the +iles window. Thiswindow is particularly useful for accessing and customi8ing your build scriptand for browsing your pro"ect outputs, such as the pro"ect9s W* file and itscontents.

• reating and maintaining an nt script, which is used when you run typicalcommands such as Build $ro"ect and *un $ro"ect. mong other things, the

nt script automates the placement of your files in the built application, the pac!aging of those files into a W* file, and deployment to the specifiedserver.

Project View of Web Applications

The $ro"ects window provides a :logical; representation of the application9s source structure,with nodes for the following#

• Web $ages (for /T01, &$, and image files that users of the application willhave direct access to through their Web browsers)

• &ource $ac!ages (for ava source pac!ages, which in turn contain servletsand other ava classes).

• Test $ac!ages (for unit tests)

• onfiguration +iles (for your deployment descriptor and other files)

• Web &ervices (where you can create and register Web services < see hapter 7 for more on development of Web services)

• 1ibraries (where you can add libraries or include the results of other IDE pro"ects)

• Test 1ibraries (where you can add any libraries necessary for running unittests on your application)

File View of Web Applications

If you open the +iles window, you will see the physical organi8ation of the files on dis! (asshown in +igure =%5) and find that this organi8ation is consistent with the pacherecommendation for organi8ing source files (see Web pplication &tructure on page >>>). TheIDE also adds the nbproject (to hold pro"ect metadata) and test (for unit tests) folders, butthese are not included in the final built application.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, %

Page 4: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 4/28

Figure 6-1 Files window with Web application folder structure

When you build the application, either through the IDE or by directly running an nt target,a build folder is created to hold the compiled classes and the dist folder is created to hold thegenerated W* file as seen in +igure =%4.

Figure 6-2

 Files window showing the structure of the built WAR file

Web Application Structure

 Ap!che 4!9!rt! provides guidelines on ho) to structure your We!pplic!tions to ensure th!t they )or9 properly )ith the 1omc!t server.When you cre!te ! pro'ect in the ID$ !nd select the 4!9!rt! sourcestructure, this structure is respected. @Simil!rly, you c!n !lso set up !pro'ect to use the 4!v! ;lue&rints structure, )hich is pre#erred i# you )ille deploying to the Sun 4!v! System Applic!tion Server.

1he #ollo)ing is ! <uic9 rundo)n on the import!nt structur!l elements o# the uilt !pplic!tion !ccording to the 4!9!rt! guidelinesB

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions,

Page 5: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 5/28

• 1he root #older @9no)n !s the document !se, )hich cont!ins !ll o# the other #iles in #olders in the !pplic!tion.

• *iles th!t !re directly !v!il!le to the users o# the !pplic!tion throughtheir We ro)sers, such !s =1M+ #iles, im!ges, !nd 4S& #iles.

• 1he WEB-INF #older, )hich cont!ins the deployment descriptor #ile

@web.xml !nd the classes, lib, tags, !nd other #olders !nd #iles.1he contents o# WEB-INF comprise the ul9 o# the !pplic!tion !nd !renot directly !v!il!le to users.

• 1he classes #older cont!ins compiled cl!ss !nd servlet #iles )ith their p!c9!ge hier!rchy re#lected y su#olders.

ou c!n #ind !ddition!l in#orm!tion on 1omc!t source structure !thttpB'!9!rt!.!p!che.orgtomc!ttomc!t5.0doc!ppdevsource.html.

See 1!le 83 #or in#orm!tion on ho) the v!rious source elements o# !We !pplic!tion m!p to their represent!tion in the ID$ !nd )here theyend up in the deployed !pplic!tion.Table 6-1: Matrix of Web Application Eleents and Their Representation in the !"E 

Content Representation in theProjects Window

Representation in the FilesWindow

Location Within the BuiltWAR File (located in thedist older!

Web pages Web $ages node   web folder root of the file

ava source files, servlets,etc.

&ource $ac!ages node   src folder WEB%IN+?classes folder

unit tests Test $ac!ages node   test folder N?

deployment descriptor (web.xml)

onfiguration +iles node   web/WEB-INF folder    WEB-INF folder 

Tomcat conte-tconfiguration file(context.xml)

web/META-INF folder   META-INF folder 

libraries 1ibraries node   web/WEB-INF/libfolder 

WEB-INF/lib folder

Test classpath entries Test 1ibraries node test folder N?

 pro"ect metadata including build script

$ro"ect $roperties dialog bo-, which you can open byright%clic!ing the pro"ect9snode and choosing$roperties.

 build.-ml file, nbpro"ectfolder 

 N?

 Adding Files and Libraries to Your Web Application

@nce you have created a Web pro"ect through the New $ro"ect wi8ard, you can start populating it with Web pages and code.

The most straightforward way to create files is by opening the $ro"ects window and right%clic!ing the pro"ect9s node or the specific folder where you want to place the file and choosing

 New and then a template from the submenu. &ee +igure =%3. short wi8ard appears for thetemplate enabling you to set the name and other characteristics of the file. In general, the wi8ard

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 5

Page 6: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 6/28

guides you to help ma!e sure that the files are placed in an appropriate directory to fit thestructure of a well%designed Web application.

NetBeans IDE Tip

1he >e) sumenu o# ! node:s conte/tu!l menu directly displ!ys !selection o# commonly used templ!tes. I# you )!nt to see the #ullselection, choose >e) E *ile*older.

1he templ!tes !re grouped into sever!l c!tegories, such !s 4!v!Cl!sses, We, D!t!!se. In !ddition to servlet !nd 4S& #ile templ!tes,the We c!tegory cont!ins templ!tes #or #ilters, We !pplic!tionlisteners, t!g #iles, !nd t!g h!ndlers, )hich cont!in use#ul s!mple code#or those speci#ic types o# #iles.

Figure 6-"#reating a new ser$let fro a pac%age&s contextual enu

onceptually, files in a Web application brea! down into a few different types of files, thefunction of which determines where you place the file in the application. The main types of filesthat you need to add to the pro"ect are#

• Web pages and other public files, meaning files that users of the applicationcan access directly through their Web browsers. Typically these include &$files, /T01 files, and image files.

• $rivate files, meaning files that are not directly viewable to the end users andwhich typically do the bul! of the processing in the application. Theseinclude ava classes, &$ files, servlets, and tag libraries and end up withinthe web?WEB-INF/classes folder of the compiled Web application.

• E-ternal resources, files created outside of the pro"ect that the files in the

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 8

Page 7: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 7/28

 pro"ect depend on. These can include tag libraries, * files that are outputfrom other IDE pro"ects, and other * files and are !ept within the WEB-INF/lib folder of the compiled Web application.

In addition, there are configuration files such as the deployment descriptor (web.xml) andfiles specific to the server you are deploying to, but the IDE generates and maintains these files

for you. +or e-ample, if you create a servlet in the IDE, the servlet is registered in the web.xmlfile automatically.

NetBeans IDE Tip

1!g lir!ries c!n e !dded to your We !pplic!tion !s lir!ries or !ssource. See Adding 1!gs !nd 1!g +ir!ries on p!ge FFF #or morein#orm!tion on )or9ing )ith t!g lir!ries.

Creating Web Pages and Oter P!blic Files

'enerally you add Web pages and other public files directly within the Web $ages node of the $ro"ects window or in a folder of your creation within that node. When the application is

 built, these files are placed by the pro"ect9s nt script in the application9s web folder.

To add a publicly viewable /T01 file, right%clic! the Web $ages node and choose New A/T01.

To add a publicly viewable &$ file, right%clic! the Web $ages node and choose New A &$.The ensuing wi8ard enables you to specify whether the &$ file uses standard synta- (and has the.jsp e-tension) or uses >01 synta- (has the .jspx e-tension). ou can also have the filecreated as a fragment (using the .jsp e-tension), which you would later reference from other 

 pages with include statements.

Creating Classes" #er$lets" and Oter Pri$ate Files

s with general ava pro"ects, classes are organi8ed within pac!ages under the &ource$ac!ages node. +or most pro"ects, this node corresponds with a folder on your dis! called src.

When the application is built, these files are placed by the nt script in the application9s WEB%IN+?classes directory.

To add a class to your pro"ect, right%clic! the &ource $ac!ages node or the node of a specific pac!age and choose New A ava lass. If you have not created any pac!age for the class you areadding, you can do so in the wi8ard as you are creating the class.

To add a servlet to your pro"ect, right%clic! the &ource $ac!ages node or the node of aspecific pac!age and choose New A &ervlet. The wi8ard for creating the servlet also guides youthrough registering the servlet in the application9s deployment descriptor (web.xml file).

If you would li!e to add a file based on a more specific template, right%clic! a pac!age nodeand choose New A +ile?+older to get a broader list of templates, including some for avaBeanscomponents, .properties files, >01 files, and speciali8ed Web components. Note that manyof the Web templates have useful s!eleton code and suggestions within the comments to get you

started on developing these !inds of ob"ects.

&ee Table =%4 for a list of templates that you can find in the Web category of the New +ilewi8ard.

Table 6-': Web Teplates

#e$plate %escription

&$ Enables you to create a &$ file (standard synta-), &$ document (>01synta-), or a &$ fragment (which would be statically referenced from another file).

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions,

Page 8: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 8/28

#e$plate %escription

&ervlet reates a ava class which e-tends the "ttp#er$let class. lso enables

you to register the servlet in the pro"ect9s deployment descriptor (web.xml)

file.

+ilter reates a ava class which implements the ja$ax.ser$let.Filterinterface. +ilters enable you to modify /TT$ re2uests to a servlet and

responses from the servlet. In the wi8ard, you can create either a basic filter or one that wraps the &ervlet*e2uest and &ervlet*esponse ob"ects.

In the template9s wi8ard, you can register the filter in the pro"ect9sdeployment descriptor (web.xml) file.

Web pplication 1istener reates a ava class which implements one or more of the listener interfacesavailable for servlets, such as #er$let%ontext&istener and

"ttp#ession&istener. Depending on the interfaces you select the

wi8ard, the created class will listen for events, such as when servlet conte-tsis initiali8ed or destroyed, the servlet session is created or destroyed, or whenattributes are added to or removed from a conte-t or session.

In the template9s wi8ard, you can register the listener in the pro"ect9sdeployment descriptor (web.xml) file.

Tag 1ibrary Descriptor reates a descriptor for a custom tag library. ou can then register tag files

and tag handlers in this file manually or when you use the New +ile wi8ard tocreate new tag files and tag handlers.

Tag +ile reates an empty .tag file with comments suggesting &$ synta- elements

that you can use to create a custom tag.

Tag /andler reates a ava class for custom &$ tags. The template includes codecomments with sample code and suggestions for how you might go aboutcreating the custom tags.

/T01 reates an /T01 with the basic tags entered.

Web &ervice reates a simple Web service. &ee hapter 7 for more information one-tending Web services with Web applications.

0essage /andler reates a &@$%based message handler for Web services. &ee hapter 56 for  more information on consuming Web services with Web applications.

Web &ervice lient reates a Web service client based on &* 567. &ee hapter 7 for moreinformation on consuming Web services with Web applications.

Adding E%ternal &eso!rces to 'o!r Project

If your Web application needs to be pac!aged with any libraries, you can add them throughthe 1ibraries node. If your pro"ect has been set up to wor! with the Tomcat server, the &$ andservlet libraries are included automatically and listed under a subnode for the Tomcat server.

ou can add e-ternal resources to your pro"ect in one of the following three forms#

• n individual folder or * file.

• cluster of resources (or :library;). This cluster might include multiple * files, sources for the * files (which are necessary for code completion or if you want to step through the library9s code with the debugger), and avadocdocumentation. ou can create such a cluster in the 1ibrary 0anager (Toolsmenu).

• The output of another IDE pro"ect.

To add an individual folder or * file to your pro"ect, right%clic! the 1ibraries node of your  pro"ect, choose dd *?+older, and navigate to the folder or * file in the file chooser.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions,

Page 9: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 9/28

 To add a cluster of related resources to your pro"ect, right%clic! the 1ibraries node, choosedd 1ibrary, and select the library from the list in the dd 1ibrary dialog bo-. If the library youare loo!ing for is not there, you can add it to the list by choosing 0anage 1ibraries.

NetBeans IDE Tip

;esides providing ! )!y to cluster resources, the +ir!ry M!n!ger m!9esit e!sy to !ccess commonly used resources. $ven i# you do not need tocluster resources, you still might )!nt to !dd individu!l resources to the+ir!ry M!n!ger to s!ve yoursel# #rom h!ving to dig through #ile choosersto !dd resources to other pro'ects.

To add the results of another IDE pro"ect, right%clic! the 1ibraries node of the current pro"ect, choose dd *?+older, and navigate to the pro"ect9s folder on your dis!. In the file

chooser, NetBeans IDE pro"ect folders are mar!ed with the icon.

NetBeans IDE Tip

I# you )!nt to !dd ! 4A" #ile or the output o# ! pro'ect to the WA" #ile)ithout m!9ing it p!rt o# the pro'ect:s compil!tion cl!ssp!th, you c!n doso through the &!c9!ging node in the &ro'ect &roperties di!log o/. SeeCustomi6ing Contents o# the WA" *ile on p!ge FFF.

Adding Tags and Tag (ibraries

Tags and tag libraries can be added to a Web pro"ect in any of the following forms#

• $ac!aged in a * file containing a tag library descriptor file (T1D) and theassociated tags, in the form of tag files (using &$ synta-) and?or tag handlers(written in ava). &uch tag libraries appear in a Web application9s WEB-INF/lib folder or in the server9s shared libraries folder. ou can add a taglibrary to a Web pro"ect through the Web pro"ect9s 1ibraries node (seedding E-ternal *esources to our $ro"ect on page >>>).

If you are developing a tag library from scratch, you can create a ava 1ibrary pro"ect for library and then add that library to a Web pro"ect by right%clic!ingthe pro"ect9s 1ibraries node and choosing dd $ro"ect. &ee hapter 3 for information on creating ava 1ibrary pro"ects.

• s tag files (using either standard or document synta-) included in the Webapplication9s WEB-INF/tags folder. ou can add new tag files to your 

 pro"ect by right%clic!ing the pro"ect9s node and choosing New A +ile?+older and then selecting the Tag +ile template from the Web category in the wi8ard.

• s a T1D file located in the WEB-INF/tlds folder and tag handlers (writtenas ava files) within the &ource $ac!ages node. ou can add new T1D filesand tag handlers to your pro"ect by right%clic!ing the pro"ect9s node andchoosing New A +ile?+older and then selecting the templates from the Webcategory in the wi8ard.

Editing and Refactoring Web Application Files

The IDE9s &ource Editor provides a lot of features that ma!e typing and changing of code for various Web application components easier. This section goes over a few of the features that are

 particularly useful for Web applications. &ee hapter C for more information on IDE editing andrefactoring features.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions,

Page 10: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 10/28

Co)pleting Tags

The IDE enables you to have tags and tag attributes completed automatically in &$, /T01,and >01 files. The tag completion feature not only reduces the number of !eystro!es that youtype but it also provides popup documentation for the possible ways to complete the tag or attribute that you are typing as shown in +igure =%C.

Figure 6-&The code copletion feature in a ()* File

@pen up the tag completion popup by typing the beginning of a tag and pressing trl%&paceor waiting a second for code completion to !ic! in automatically. If there is only one way tocomplete the word you are typing, the end of the word is filled in automatically. If there aremultiple ways to complete the tag, a popup list of those possibilities is displayed. ou can !eeptyping to narrow the list or select the te-t you want using the mouse or arrow !eys to select theword you want.

+or e-ample, if you want to add the following statement in a &$ file#

'jsp(useBean id)*+ello* scope)*page*class)*org.m,domain.m,pacage.M,%lass* /

you can enter it in the following steps (don9t worry < the number of steps illustrated here mayseem daunting, but it is only because they are presented in such minute detail)#

5. Type 'jsp(u

4. $ress trl%&pace (seBean is appended).

3. Type i

C. $ress trl%&pace (d) is appended with the insertion point left between the

2uotation mar!s).

. Type +ello

=. $ress the right arrow !ey and then the spacebar 

. Type s

F. $ress Enter (cope) is appended with the insertion point left between the2uotation mar!s).

7. Type p

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 30

Page 11: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 11/28

56.$ress trl%&pace (age is appended).

55.$ress the right arrow !ey twice.

54.Type c

53.$ress Enter (lass) is appended with the insertion point left between the2uotation mar!s).

5C.Type o5.$ress trl%&pace (rg is appended, assuming that the class is part of your 

 pro"ect).

5=.Type a period (.) and press trl%&pace (m,domain is filled in).

5.Type a period (.) and press trl%&pace (m,pacage is filled in).

5F.Type a period (.) and press trl%&pace (M,%lass is filled in).

57.$ress the right arrow !ey twice and type /

&ee hapter C# 'enerating ode &nippets for information on completing ava e-pressionsand configuring code completion.

E%panding Abbre$iations for *#P Files

+or commonly used &$ code snippets, you can ta!e advantage of abbreviations in the&ource Editor to reduce the number of !eystro!es. bbreviations are e-panded when you typethe abbreviation and then press the spacebar.

&ee Table =%3 for a list of abbreviations for &$ files. ou can also e-pand abbreviations for other types of files. &ee hapter C, Table C%5 for a list of abbreviations for ava classes.

If an abbreviation is the same as a te-t that you want to type (i.e. you do not want it to bee-panded into something else), press &hift%&pace to !eep it from e-panding.

ou can modify the list of abbreviations in the bbreviations dialog bo- for a type of file.&ee hapter C, dding, hanging, and *emoving bbreviations.

Table 6-+: ()* Abbre$iations in the )ource Editor 

A''reiation )*pands to

ag application.getGalue(H

ap application.putGalue(H

ar application.removeGalue(H

cfgi config.getInit$arameter(H

oup out.print(H

oupl out.println(H

 pcg pageonte-t.getttribute(H

 pcgn pageonte-t.getttributeNamesIn&cope(

 pcgs pageonte-t.getttributes&cope(H

 pcr pageonte-t.removettribute(H

 pcs pageonte-t.setttribute(H

rg re2uest.get$arameter(H

sg session.getGalue(H

sp session.putGalue(H

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 33

Page 12: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 12/28

A''reiation )*pands to

sr session.removeGalue(H

 "spf "sp#forward pageJH

 "g "sp#get$roperty nameJH

 "spg "sp#get$roperty nameJH

 "spi "sp#include pageJH

 "spp "sp#plugin typeJH

 "sps "sp#set$roperty nameJH

 "spu "sp#useBean idJH

 pg KL page

 pga KL page auto+lushJH

 pgb KL page bufferJH

 pgc KL page contentTypeJH

 pgerr KL page error$ageJH

 pge- KL page e-tendsJH

 pgie KL page isError$ageJH

 pgim KL page importJH

 pgin KL page infoJH

 pgit KL page isThread&afeJH

 pgl KL page languageJH

 pgs KL page sessionJH

tglb KL taglib uriJH

+an!all, Editing te Deplo,)ent Descriptor Though the IDE guides you through the adding of entries for the deployment descriptor 

(web.xml file) as you add servlets, filters, and listeners to your pro"ect, you might have occasionto edit the file by hand.

To open the deployment descriptor in the &ource Editor, open the $ro"ects window, e-pandthe onfiguration +iles node (or the Web $ages A Web%IN+ node) and double%clic! the web.xmlfile. The file opens as a multi%tab document in the &ource Editor with the @verview tab open (asseen in +igure =%). ou can edit different parts of the web.xml file with the visual editors for different elements of the file (@verview, &ervlets, +ilters, and $ages) or you can clic! the >01tab to directly edit the file9s >01 source (see +igure =%=).

Figure 6-+

 "eplo,ent descriptor $isual editor 

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 32

Page 13: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 13/28

Figure 6-6 "eplo,ent descriptor M. editor 

&efactoring Web Co)ponents

 NetBeans IDE9s refactoring support e-tends to Web applications and enterprise applications.+or e-ample, you can do the following#

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 3%

Page 14: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 14/28

• *ename classes, methods, and fields of servlets, tag handlers, and other Webcomponents. &ee hapter C, *enaming ll @ccurrences of the urrently&elected lass, 0ethod, or +ield Name

• 0ove classes to a different pac!ages or pro"ects (resulting in the class being pac!aged in a different W* file). &ee hapter C, 0oving a lass to a

Different $ac!age.• hange method parameters including parameter names, parameter types,

method visibility, adding method parameters or removing method parameters.&ee hapter C, hanging a 0ethod9s &ignature.

• hanging visibility of fields and adding getter and setter accessor methods.&ee hapter C, 'enerating *ead?Write $roperties.

When you rename a Web component class (such as a servlet or tag handler), anycorresponding name entries in the application9s deployment descriptor (web.xml file) and?or taglibrary descriptor (T1D) are updated as well. When you move a class and the deploymentdescriptor as affected, you are prompted with a onfirm hanges dialog bo- to ma!e sure thatyou want to process changes to the deployment descriptor.

I)portant;e c!re#ul not to ren!me or ch!nge the p!r!meters o# ! servlet methodth!t must e implemented )ith ! given n!me !ccording to the Servlet or $nterprise 4!v!;e!ns speci#ic!tions.

Deploing a Web Application

By default, a Web application is deployed to the server you have specified when you run that pro"ect.

+or applications that you deploy to the Tomcat server, the application is deployed :in place;,meaning that the IDE creates an >01 file that is placed in the server9s

con/%atalina/local+ost/ directory and points Tomcat to the IDE pro"ect9s build directorywhere the applications files reside.

When you build a Web pro"ect in the IDE, a W* file is also created, which you canmanually deploy to a server.

C!sto)i-ing Contents of te WA& File

By default, a Web pro"ect9s generated W* file includes#

• ll files displayed within the pro"ect9s Web $ages node, including the

web.xml and context.xml files.

• ompiled class files of the source files within ava &ources node plus any

other files placed there without the .ja$a and .orm file e-tensions.• ny libraries that you have added to the pro"ect9s 1ibraries node.

ou can also add * files to the W* file and filter out contents that would normallyappear.

To customi8e a W* file9s contents#

5. *ight%clic! the pro"ect9s node in the $ro"ects window and choose $roperties.

4. &elect the Build A $ac!aging node.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 3

Page 15: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 15/28

3. If you want to filter out contents from the generated W* file, modify theregular e-pression in the E-clude +rom W* +ile field.

C. If you want to add additional folders or files, do so through dd *?+older,dd 1ibrary, or dd $ro"ect buttons.

The dd *?+older button enables you to add individual * files or 

folders, whether or not they come from IDE pro"ects.The dd 1ibrary button enables you to add any * files or clusters of * files that you have designated in the IDE9s 1ibrary 0anager.

The dd $ro"ect button enables you to add the * file that is output fromanother IDE pro"ect. When you add an IDE pro"ect to the W* file, that

 pro"ect9s * file is rebuilt every time you build the Web application pro"ect.

.ndeplo,ing a Web Application

When you stop a Web application that you have run through the IDE, the application stillremains deployed through a reference to that application in the form of an >01 file in Tomcat9scon/%atalina/local+ost directory.

To undeploy an such an application from Tomcat#

5. @pen the *untime window.

4. E-pand the &ervers node, then e-pand the node for the Tomcat server and theserver9s Web pplications node.

3. *ight%clic! the node for the running Web application and choose Mndeploy.

&edeplo,ing a Web Application

To remove your application from the server and then redeploy it, right%clic! the pro"ect9snode and choose *edeploy $ro"ect.

Creating a WA& File

When you run the Build $ro"ect command on a Web pro"ect in the IDE, a W* file iscreated automatically and placed in the dist folder of the pro"ect. ou can access this file and

 browse its contents in the +iles window.

Deplo,ing to a Different To)cat #er$er 

The IDE comes bundled with the Tomcat server, which facilitates Web applicationdevelopment and testing. If you have a different Tomcat installation that you want to test onand?or deploy to, you can register that installation with the IDE. ou can easily switch your application to wor! with the different server installations. This is particularly useful if you want

to develop and test on one installation and then deploy to a production environment.To set up the IDE to recogni8e a different Tomcat installation#

5. hoose Tools A &erver 0anager .

4. lic! the dd &erver button.

3. @n the hoose &erver page of the wi8ard that opens, select a server from the&erver combo bo-, enter an IDE display name for that server in the Namefield, and clic! Ne-t.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 35

Page 16: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 16/28

C. @n the Tomcat &erver Instance $roperties page, specify the Tomcatinstallation directory (and base directory if it is a shared installation) and fillin a user name and password.

ou can also determine whether to enable the IDE9s /TT$ 0onitor. If the/TT$ 0onitor is enabled, you can monitor your application9s server re2uests,coo!ies, and so on, which ma!es it easier to debug your application.

/owever, this option slows down the server, so you will probably want thisoption disabled if you are using this is your production server. &ee0onitoring /TT$ Transactions on page >>> for information on using the/TT$ 0onitor.

. Gerify that the server is not using a port number used by another server. Inthe IDE, you can view the server9s port number by mousing over the server9snode and viewing the node9s tooltip.

If another server instance is using the same port, you need to stop one of theservers and change the port it is using. &top the server right%clic!ing theserver9s node, choosing &tart?&top &erver and clic!ing &top &erver. Thenright%clic! the server node, choose $roperties, and change the &erver $ort

 property. *estart the server by right%clic!ing the node, choosing &tart?&top&erver and clic!ing &tart &erver.

=. If you have any e-isting Web applications within the IDE that you want torun on the newly added server, modify the properties for each pro"ect to usethe server. ou can do so by right%clic!ing the pro"ect9s node in the $ro"ectswindow, choosing $roperties, selecting the *un node, and choosing the server from the &erver combo bo-.

NetBeans IDE Tip

I# you l!ter )!nt to ch!nge the server:s con#igur!tion, you c!n !ccess theserver:s properties opening the "untime )indo), e/p!nding the Serversnode, rightclic9ing the speci#ic server:s node !nd choosing &roperties.

!esting and Debugging Your Web Application

 NetBeans IDE provides a rich environment for troubleshooting and optimi8ing your Webapplications. &ome of the features to ease testing of Web applications include#

• The ompile &$ command, which enables you to chec! individual &$ filesfor errors before deploying to the server.

• Debugger integration with &$ files, which means that you can set brea!points in &$ files and step through &$ in the debugger (as opposed tohaving to step through the generated servlet code).

• bility to step through tag files.

• bility to evaluate E-pression 1anguage (E1) e-pressions in &$ files duringa debugging session (by mousing over the e-pression or setting a watch).

• The /TT$ 0onitor, which !eeps trac! of /TT$ communication betweenservlets and the server. This feature is covered in detail under 0onitoring/TT$ Transactions on page >>>.

&ee hapter for more information on the IDE9s general debugging features that thesefeatures e-tend.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 38

Page 17: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 17/28

Cec/ing For *#P Errors

&$ files are not compiled li!e typical ava files before they are deployed. Instead, they arecompiled by the server after they have been deployed (where in fact they are first translated toservlets, which are then compiled). This ma!es it more cumbersome to correct errors thatnormally are detected when compiling, since it forces you to deploy the application, discover the

error, undeploy, correct the error, and redeploy./owever, NetBeans IDE enables you to compile &$ files to chec! for errors before you

 pac!age and deploy the application. ou can either compile individual &$ files manually or specify that they be compiled when you build the pro"ect.

To compile a &$ file manually, select the file in the $ro"ects window or in the &ource Editor and select Build A ompile +ile or press +7.

To have all &$ files compiled when you run the Build $ro"ect command, right%clic! the pro"ect9s node, choose $roperties, select the ompiling node, and select the Test ompile ll &$+iles During Builds chec!bo-.

The compilation results are reported in the @utput window, where you can discover anyerrors, whether they occur in the translation to the servlet or in the compilation of the servlet.

The compiled files themselves are placed in the pro"ect9s build/generated folder, whichyou can view from the +iles window. These files are not used when you are building and pac!aging the application for deployment.

Viewing a *#P File0s #er$let

The generation of a servlet from a &$ file happens dynamically on the server where the Webapplication is deployed. ou can view this generated servlet once you have run the pro"ect or thespecific &$ associated with it by right%clic!ing the file and choosing Giew &ervlet.

NetBeans IDE Tip

I# you )ould li9e to see the servlet code th!t is gener!ted )hen you runthe Compile 4S& comm!nd, open the *iles )indo) open the

build/generated/src #older, !nd n!vig!te to the #ile )hich is n!med

!ccording to the 4S& #ile n!me, ut )ith ! 0jsp su##i/ !nd .ja$ae/tension.

Viewing a File in a Web Browser 

ou can open components of a Web application in a Web browser from the IDE.

To view a specific &$ page in a Web browser, you need to run that file individually (byright%clic!ing the file in the &ource Editor or pressing &hift%+=).

To open an /T01 file in the Web browser, right%clic! the /T01 page9s node in the $ro"ectswindow and choose Giew.

NetBeans IDE Tip

1he (ie) comm!nd #or =1M+ #iles is not !v!il!le #rom the Source$ditor. I# you )!nt to vie) the current =1M+ #ile in the Source $ditor )ithout your #ingers le!ving the 9eyo!rd, press CtrlShi#t3 to 'ump to the#ile:s node in the &ro'ects )indo), press Shi#t*30 to open the node:sconte/tu!l menu, press the do)n !rro) to select (ie), !nd press $nter.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 3

Page 18: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 18/28

Passing &e1!est Para)eters to a Web Application

ou can manually test the way the Web application will respond to certain input by runningthe application with certain re2uest parameters specified ahead of time.

To pass re2uest parameters to a &$ page#

5. *ight%clic! the &$ file9s node and choose $roperties.

4. In the *e2uest $arameters property, enter the parameters in M*1 2uery stringformat (where the e-pression begins with a M*1, continues with a 2uestionmar! () to mar! the beginning of the 2uery, and completed with the

 parameters as name?value pairs, where the pairs separated by ampersands(O)).

To pass re2uest parameters to a servlet#

5. *ight%clic! the servlet9s node in the $ro"ects window, and choose Tools A &et&ervlet E-ecution M*I.

4. In the dialog bo-, append a 2uestion mar! plus the name?value pairs, witheach pair separated by an ampersand.

Deb!gging *#P and Tag Files

@ne of the IDE9s features that has long made NetBeans IDE a favorite with Web developersis the ability of the debugger to step into &$ files. ou can set brea!points in &$ files and stepthrough the &$ line by line while monitoring the values of variables and other aspects of therunning program.

 NetBeans IDE C.5 adds the ability to step into tag files.

To set a brea!point in a &$ or tag file, select the line where you would li!e to pausee-ecution and press trl%+F. &ee hapter for more information on debugging.

"reating and Deploing Applets

 NetBeans IDE does not have a specific pro"ect type for applets, so the development cycle for applets is a little different than for other types of pro"ects. ou can not designate an applet as amain pro"ect, which means that several pro"ect%specific commands (such as *un $ro"ect) do notapply to applets.

/owever, you can still create, test, and deploy applets fairly easily. The general outline of applet development is as follows#

5. reate a ava 1ibrary pro"ect to hold the applet.

4. reate an applet from one of the templates in the New +ile wi8ard and fill incode for the applet.

3. Test the applet in the DP9s applet viewer by right%clic!ing the applet9s nodein the $ro"ects window and choosing *un +ile.

C. reate a * file for the applet by right%clic!ing the applet9s pro"ect node andchoosing Build $ro"ect.

. If you want to add the applet to a Web application, add the applet9s pro"ect (or  "ust the applet9s * file) through the Web pro"ect9s 1ibraries node.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 3

Page 19: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 19/28

Creating an Applet

To create an applet#

5. hoose New $ro"ect, select the 'eneral category, select the ava 1ibrarytemplate, and clic! Ne-t.

4. Enter a name and location for the pro"ect and clic! +inish to e-it the wi8ard.

3. In the $ro"ects window, e-pand the node for the pro"ect you have "ust created.Then right%clic! the &ource $ac!ages node and choose New A +ile?+older.

C. In the New +ile wi8ard, select one of the available applet templates. There arefour available#

• ava lasses category, pplet template. This template e-tends

ja$ax.swing.1Applet and is recommended over the pplettemplate, which is based on the less fle-ible ja$a.applet.Appletclass.

• ava 'MI +orms category, pplet template. This template e-tendsja$ax.swing.1Applet and enables you to use the IDE9s +ormEditor to visually design your applet. This template is recommended

over the pplet template in the WT +orms sub%category.• ava lasses category, pplet template. This template e-tends

ja$a.applet.Applet.

• ava 'MI +orms A WT +orms category, pplet template. Thistemplate e-tends ja$a.applet.Applet and enables you to use theIDE9s +orm Editor to visually design your applet.

lic! Ne-t, specify a name and a pac!age for the applet, and thenclic! +inish.

ou can then code the applet, either by hand or with the assistance of the +orm Editor.

&!nning and Deb!gging an Applet in te Applet Viewer 

s you are developing the applet, you can use the DP9s applet viewer to test the applet9sfunctionality. When you use the *un +ile and Debug +ile commands, the applet is automaticallydisplayed in the applet viewer.

To run an applet, right%clic! the applet9s node in the $ro"ects window and choose *un +ile.

To start debugging an applet#

5. &et a brea!point in the code by selecting the line where you first wante-ecution to pause and press trl%+F.

4. *ight%clic! the applet9s node in the $ro"ects window and choose Debug +ile.

&!nning an Applet in a Web Browser 

If you want to see how your applet behaves in an actual Web browser, you can open an/T01 launcher for the applet.

To run an applet in a Web browser#

5. @pen the +iles window and e-pand the pro"ect9s build directory.

4. *ight%clic! the /T01 launcher file (it should have the same name as theapplet class but with an /T01 e-tension) and choose Giew.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 3

Page 20: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 20/28

The applet opens in the default Web browser specified in the IDE. &ee hanging the IDE9sDefault Web Browser on page >>> if you would li!e to change the IDE9s default Web browser.

NetBeans IDE Tip

I# you )!nt to customi6e the =1M+ l!uncher #ile, you c!n copy thegener!ted l!uncher #ile into the #older th!t cont!ins the !pplet source #ile.1his prevents the l!uncher #ile #rom eing over)ritten every time you run

the !pplet.

When you run the !pplet or uild the !pplet:s pro'ect, the =1M+ #ile iscopied into the #older )ith the compiled !pplet cl!ss. I# you do not )!ntthis #ile to e included in the 4A" th!t is cre!ted )hen you uild thepro'ect, you c!n modi#y the #ilter #or the 4A" #ile:s contents. In the&ro'ects )indo), rightclic9 the pro'ect:s node !nd choose &roperties. Inthe di!log o/, select the &!c9!ging node !nd modi#y the regul!r e/pression in the $/clude *rom 4A" *ile #ield. *or e/!mple, you could!dd ! comm! plus !n e/pression li9e 22/Myapplet.+tml to m!9e sureth!t your l!uncher #ile @no m!tter )hich directory it is in is e/cluded #romthe uilt 4A" #ile.

Pac/aging an Applet into a *A& FileIf you want to put an applet into a * file, you can do so by right%clic!ing the applet9s

 pro"ect node in the $ro"ects window and choosing Build $ro"ect.

The applet is compiled and the compiled class files are placed in a * file in the distfolder, which you can view with the +iles window.

Pac/aging an Applet into a WA& File

To add an applet to a Web application#

5. $ut the applet into a * file. &ee $ac!aging an pplet into a * +ile abovefor information on how to do this in the IDE.

4. *ight%clic! the Web application9s pro"ect node in the $ro"ects window andchoose $roperties.

3. In the $ro"ect $roperties dialog bo-, select the Build A $ac!aging node.

C. lic! the dd $ro"ect button, navigate to the applet9s pro"ect folder, and clic! dd $ro"ect * +iles.

#etting Applet Per)issions

When you create and run an applet through the IDE, an applet.polic, is created with all permissions granted and is placed in the root folder of the pro"ect (which you can view throughthe +iles window). ou can modify this file by double%clic!ing its node to open it in the &ourceEditor.

ou can also specify a different policy file for the applet. To specify a different policy file#

5. *ight%clic! the Web application9s pro"ect node in the $ro"ects window andchoose $roperties.

4. In the $ro"ect $roperties dialog bo-, select the *un node.

3. In the G0 @ptions field, modify the value of the -3ja$a.securit,.polic, option to point to the policy file.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 20

Page 21: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 21/28

"hanging the IDE#s Default Web Bro$ser 

To change the IDE9s default Web browser, choose Tools A &etup Wi8ard and select a browser from the Web Browser combo bo-.

If the IDE can not find a given Web browser on your system, you might need to specify thee-ecutable for that Web browser.

To point the IDE to a Web browser that is listed in the &etup Wi8ard#

5. hoose Tools A @ptions and e-pand the IDE onfiguration A &erver andE-ternal Tools &ettings A Web Browsers node.

4. &elect the subnode for the browser that you want and modify the Browser E-ecutable property.

To add to the IDE9s list of Web browsers#

5. hoose Tools A @ptions and e-pand the IDE onfiguration A &erver andE-ternal Tools &ettings A Web Browsers node.

4. *ight%clic! the Web Browsers node, choose New A E-ternal Browser, type the browser9s name, and clic! +inish.

3. &elect the subnode for the added browser and modify the Browser E-ecutable property to point to that browser9s e-ecutable.

%onitoring &!!' !ransactions

 NetBeans IDE provides a built%in /TT$ 0onitor to help isolate problems with data flowfrom &$ and servlet e-ecution on a Web server. There is no need to add logic to your Webapplication to trace /TT$ re2uests and associated state information. The NetBeans IDE built%in/TT$ 0onitor can do this for you.

When the IDE is configured with a Web container or a Web application is deployed with a NetBeans /TT$ 0onitor servlet filter and filter mapping, the /TT$ 0onitor will automaticallyrecord all /TT$ re2uests made to the Web container. +or each /TT$ re2uest that is processed

 by the Web container, the /TT$ 0onitor not only records the re2uest, it also records stateinformation maintained in the Web container.

By using the /TT$ 0onitor, you can analy8e /TT$ re2uests, and store /TT$ 'ET and/TT$ $@&T re2uests for future analysis sessions. ou can also edit these stored re2uests andreplay them. This is a powerful feature to help isolate data flow and state information passedwithin an /TT$ re2uest to a Web container. /TT$ re2uests are stored until you e-it the IDEunless you e-plicitly save them.

The following are some of the things that you can do with the IDE9s /TT$ 0onitor#

• naly8e /TT$ re2uests records.

• &ave /TT$ re2uest records.

• Edit /TT$ re2uest records.

• *efresh re2uest records.

• &ort /TT$ re2uest records.

• Delete /TT$ re2uest records.

• *eplay /TT$ re2uest records.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 23

Page 22: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 22/28

In the following sections, you will learn how to setup the /TT$ 0onitor, analy8e the datathe /TT$ 0onitor collects and replay recorded /TT$ re2uests.

#etting .p te 2TTP +onitor 

When you run a Web application, the /TT$ 0onitor is generally automatically enabled. If 

the /TT$ 0onitor is not displayed in the bottom of the IDE, then verify the /TT$ 0onitor isenabled by performing the following tas!s.

5. E-pand the *untime window9s &ervers node to show your registered Webserver. Then right clic! the server9s node and choose $roperties.

4. $lace a chec! bo- in the Enable /TT$ 0onitor property.

3. If the registered Web server is currently running, stop and restart it by rightclic!ing your registered Web server under the *untime window9s &erversnode and selecting &tart ? &top &erver.

+igure =%= shows the Enable /TT$ 0onitor property on the &un ava &ystem pplication&erver F $roperties dialog.

Figure 6-6, *roperties dialog box for the )un (a$a ),ste Application )er$er 

#etting .p te 2TTP +onitor For #er$ers #tarted O!tside of te IDE

ou can also use the /TT$ 0onitor on Web servers started outside the NetBeans IDE. Todo so, e-ecute the following tas!s#

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 22

Page 23: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 23/28

5. 'o to the directory where the NetBeans IDE is installed and copy themodules/org-netbeans-modules-sc+ema4beans.jar  and

modules/org-netbeans-modules-web-+ttpmonitor.jar  files to your Web module9s WEB-INF/lib directory.

4. dd a filter declaration that is appropriate for your servlet9s version to the topof your Web module9s WEB-INF/web.xml file.

+ilters and filter mapping entries must be specified at the beginning of adeployment descriptor. &ee the e-amples below for filters for the servletscorresponding the 4.3 and 4.C versions of the &ervlet specification.

&ervlet 4.C filter declaration might loo! li!e the following#

'ilter  'ilter-name"TT5MonitorFilter'/ilter-name  'ilter-class  org.netbeans.modules.web.monitor.ser$er.MonitorFilter  '/ilter-class  'init-param  'param-name  netbeans.monitor.ide  '/param-name  'param-$alue  name-of-host-running NetBeans IDE (http-server-port  '/param-$alue  '/init-param'/ilter'ilter-mapping  'ilter-name  "TT5MonitorFilter  '/ilter-name  'url-pattern  /2  '/url-pattern  'dispatc+er

  6E78E#T  '/dispatc+er  'dispatc+er  F96WA63  '/dispatc+er  'dispatc+er  IN%&83E  '/dispatc+er  'dispatc+er  E6696  '/dispatc+er'/ilter-mapping

&ervlet 4.3 filter declaration might loo! li!e the following#

'ilter  'ilter-name"TT5MonitorFilter'/ilter-name  'ilter-class  org.netbeans.modules.web.monitor.ser$er.MonitorFilter  '/ilter-class  'init-param  'param-name  netbeans.monitor.ide

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 2%

Page 24: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 24/28

  '/param-name  'param-$alue  name-of-host-running NetBeans IDE (http-server-port  '/param-$alue  '/init-param'/ilter'ilter-mapping

  'ilter-name  "TT5MonitorFilter  '/ilter-name  'url-pattern  /2  '/url-pattern'/ilter-mapping

Web application can be monitored with the IDE /TT$ 0onitor from multiple NetBeansIDEs by adding additional init-param entries to the &ervlet filter declaration in the Webdeployment descriptor. +or instance, you would an additional init%parm entry such as the oneshown below#

  'init-param  'param-name  netbeans.monitor.ide  '/param-name  'param-$alue  name-of-2nd -host-running NetBeans IDE (http-server-port  '/param-$alue  '/init-param

I+PO&TANT

When you deploy the We module you h!ve een monitoring )ith the=11& Monitor to ! production server, rememer to remove the Servlet

#ilter !nd #ilter m!pping decl!r!tions #rom the We module:s deploymentdescriptor. -ther)ise, the We module )ill e open #or =11& monitoring#rom those >et;e!ns ID$s speci#ied in the init-param section@s o# theservlet #ilter in the We module:s deployment descriptor.

Anal,-ing te Collected Data

fter you have setup the /TT$ 0onitor, you can use the /TT$ 0onitor to debug your Webapplication by observing data flow from your &$ page and servlet e-ecution on the Web server.The /TT$ 0onitor records data about each incoming re2uest. The /TT$ 0onitor isautomatically displayed in the bottom of the IDE. snapshot of the /TT$ 0onitor is shown in+igure =%.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 2

Page 25: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 25/28

Figure 6- /TT* Monitor

The /TT$ 0onitor consists of two panels. @n the left is a tree view of /TT$ re2uestrecords. Every /TT$ re2uest made to the /TT$ server is recorded in the /TT$ 0onitor.*e2uests resulting from internal dispatches are reflected by nested nodes under those Webcontainers which support it. In addition, forwarded or included re2uests are nested under thenode corresponding to the main re2uest.

Displayed on the right panel of the /TT$ 0onitor is additional data for a selected /TT$re2uest record on the left panel. When you select an /TT$ re2uest record on the left, sessiondata corresponding to the selected record is displayed in the right panel. The additional sessioninformation available in the right panel includeQ detailed re2uest information, coo!ie name ?value pairs, session data, servlet conte-t, conte-t attributes, initiali8ation parameters, client ?server information such as client protocol, client I$ address, server platform and server hostname along with additional /TT$ re2uest header information. The right panel allows you viewspecific data in each of these categories by selecting a tab corresponding to the information youwould li!e to see. +igure =% below shows the additional session information for a selected/TT$ re2uest record.

>et;e!ns ID$ *ield ?uide, Developing We Applic!tions, 25

Page 26: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 26/28

Page 27: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 27/28

Page 28: WebApps Tomcat

8/10/2019 WebApps Tomcat

http://slidepdf.com/reader/full/webapps-tomcat 28/28

In addition to replaying /TT$ re2uests, you can also edit an /TT$ re2uest before replayingit. To edit an /TT$ re2uest before replaying it, select an /TT$ re2uest in the left panel treeview, either a urrent *ecord or &aved *ecord, right clic! the record and choose the Edit and*eplay option from the conte-tual menu. N@TE# 0ultiple records and cannot be edited andreplayed. fter choosing the Edit and *eplay option, a dialog bo- is displayed where you canma!e various modifications.

The supported modifications in the Edit and *eplay of an /TT$ re2uest include options toedit a parameter to 2uery, modify re2uest M*I parameters, modify coo!ies, modify server e-ecution properties and modify /TT$ re2uest parameters.

Figure 6-1 /TT* Monitor Edit and Repla, dialog box

 @n the Ruery tab, in +igure =%56, you can add a 2uery parameter or delete a 2uery parameter and modify M*I re2uest parameters. @n the *e2uest tab, you can modify the *e2uest M*I byselecting the ellipsis (...) button ne-t to the re2uest parameter value. ou can change the re2uestmethod from a 'ET to a $@&T or $MT, by selecting the dropdown bo- to the right of the*e2uest 0ethod type in the left hand column. ou can also modify the *e2uest $rotocol by

selecting the ellipsis button ne-t in the far right column of the *e2uest $rotocol. @n the oo!iestab, you can add modify or delete coo!ies associated with the /TT$ re2uest. @n the &erver tab,you can modify server e-ecution values such as the host name and port where the /TT$ re2uestshould be e-ecuted. ou can add, modify and delete /TT$ headers under the /eaders tab.

fter ma!ing your desired edits to the /TT$ re2uest, you can replay the modified re2uest by pressing the &end /TT$ *e2uest button. The resulting /TT$ re2uest will then be sent to your Web browser where the results will be displayed.