Testing and Debugging Your Web Application


NetBeans IDE provides a rich environment for troubleshooting and optimizing your web applications. Some of the features to ease testing of web applications include:

  • The Compile JSP command, which enables you to check individual JSP files for errors before deploying to the server.

  • Debugger integration with JSP files, which means that you can set break-points in JSP files and step through a JSP in the debugger (as opposed to having to step through the generated servlet code).

  • Ability to step through tag files.

  • Ability to evaluate Expression Language (EL) expressions in JSP files during a debugging session (by mousing over the expression or setting a watch).

  • The HTTP Monitor, which keeps track of HTTP communication between servlets and the server. This feature is covered in detail in Monitoring HTTP Transactions later in this chapter.

See Chapter 7 for more information on the IDE's general debugging features that these features extend.

Checking for JSP Errors

JSP files are not compiled like typical Java files before they are deployed. Instead, they are compiled by the server after they have been deployed (where in fact they are first translated to servlets, which are then compiled). This makes it more cumbersome to correct errors that normally are detected when compiling, because it forces you to deploy the application, discover the error, undeploy, correct the error, and redeploy.

However, NetBeans IDE enables you to compile JSP files to check for errors before you package and deploy the application. You can either compile individual JSP files manually or specify that they be compiled when you build the project.

To compile a JSP file manually, select the file in the Projects window or in the Source Editor, and select Build | Compile File or press F9.

To have all JSP files compiled when you run the Build Project command, right-click the project's node, choose Properties, select the Compiling node, and select the Test Compile All JSP Files During Builds checkbox.

The compilation results are reported in the Output window, where you can discover any errors, whether they occur in the translation to the servlet or in the compilation of the servlet.

The compiled files themselves are placed in the project's build/generated folder, which you can view from the Files window. These files are not used when you are building and packaging the application for deployment.

Viewing a JSP File's Servlet

The generation of a servlet from a JSP file happens dynamically on the server on which the web application is deployed. You can view this generated servlet once you have run the project or the specific JSP associated with it by right-clicking the file and choosing View Servlet.

If you would like to see the servlet code that is generated when you run the Compile JSP command, open the Files window; open the build/generated/src folder; and navigate to the file, which is named according to the JSP filename but with a _jsp suffix and .java extension.


Viewing a File in a Web Browser

You can open components of a web application in a web browser from the IDE.

To view a specific JSP page in a web browser, you need to run that file individually by right-clicking the file in the Source Editor and choosing Run File (or pressing Shift-F6).

To open an HTML file in the web browser, right-click the HTML page's node in the Projects window and choose View.

The View command for HTML files is not available from the Source Editor. If you want to view the current HTML file in the Source Editor without your fingers leaving the key-board, press Ctrl-Shift-1 to jump to the file's node in the Projects window, press Shift-F10 to open the node's contextual menu, press the down-arrow key to select View, and press Enter.


Passing Request Parameters to a Web Application

You can manually test the way the web application will respond to certain input by running the application with certain request parameters specified ahead of time.

To pass request parameters to a JSP page:

  1. Right-click the JSP file's node and choose Properties.

  2. In the Request Parameters property, enter the parameters in URL query string format (where the expression begins with a URL; continues with a question mark [?] to mark the beginning of the query; and completes with the parameters as name/value pairs, where the pairs are separated by amper-sands [&]).

To pass request parameters to a servlet:

  1. Right-click the servlet's node in the Projects window and choose Tools | Set Servlet Execution URI.

  2. In the dialog box, append a question mark plus the name/value pairs, with each pair separated by an ampersand.

Debugging JSP and Tag Files

One of the IDE's features that has long made NetBeans IDE a favorite with web developers is the capability of the debugger to step into JSP files. You can set breakpoints in JSP files and step through the JSP line by line while monitoring the values of variables and other aspects of the running program. In addition, you can step into tag files.

To set a breakpoint in a JSP or tag file, select the line where you would like to pause execution and press Ctrl-F8. See Chapter 7 for more information on debugging.



NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net