NetBeans IDE provides a rich environment for troubleshooting and optimizing your web applications. Some of the features to ease testing of web applications include:
See Chapter 7 for more information on the IDE's general debugging features that these features extend. Checking for JSP ErrorsJSP 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 ServletThe 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.
Viewing a File in a Web BrowserYou 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.
Passing Request Parameters to a Web ApplicationYou 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:
To pass request parameters to a servlet:
Debugging JSP and Tag FilesOne 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. |