Debugging JSP with Lomboz

Source: Internet
Author: User
Tags java web tomcat apache tomcat
JS Preface
Anyone who has the experience of JSP writing has JSP debugging difficult experience. The lack of automated debugging tools makes it necessary to use a large number of print statements in a file when debugging JSP. This approach is a simple and effective way to locate bugs within the JSP range, but it is a bit too much to quickly and efficiently locate internal errors in the objects that are invoked in the JSP. Because this will have to frequently compile, release, start and stop the server, to the debugging brings great inconvenience.

The legend of the WYSIWYG JSP debugging tools, as I currently grasp the situation, does not exist. If the reader has information on this aspect of the hope to inform, hehe. But the JSP debugging tool does exist, and it is free! It ' s lomboz. Download Address: http://www.objectlearn.com/products/download.jsp

This article starts with a simple example to describe how to debug a JSP using Lomboz. The development environment for this example is as follows:

-JDK version: 1.4.1;

-java Ide:eclipse 2.1;

-lomboz: Suitable for Eclipse2.1 plug-ins;

-jsp/servlet container: Tomcat 4.1.18.

Lomboz Introduction
Strictly speaking, Lomboz is an Eclipse plug-in that integrates many Java application servers, EE components, and Web application development into eclipse to help Java developers build, test, and deploy EE applications using Eclipse. For the focus of this article, JSP debugging, it also has related support:

-Support JSP writing, including: syntax coloring and grammar checking;

-Support for JSP debugging.

For JSP debugging, the principle of Lomboz is to debug the JSP page generated by the Java code to debug. The entire debugging process is the same as debugging the Java application, so that the debugging of the JSP itself is seamlessly connected to the debugging of the object being invoked by the JSP.

Before we begin the example of this article, let's take a look at the installation of Lomboz and the configuration for the normal use of its JSP debugging features.

Installation and Configuration
The Lomboz installation process is very simple, and most of the Eclipse plug-in installation process is very simple, the main steps are as follows:

1. Download the plugin that supports Eclipse2.1 (or other versions of Eclipse) from the Lomboz download address (http://www.objectlearn.com/products/download.jsp).

2. If eclipse is already running, please close it first.

3. Extract the downloaded files into the plugins directory under the Eclipse installation directory.

4. Restart Eclipse and open "about Eclipse Platform plug-ins" (Help-> about Eclipse Platform->plug-in Details), If the Lomboz installation succeeds, information about it will appear. The following figure:


Note: If you want to unload the Lomboz, you only need to delete the plugins directory corresponding to the Lomboz directory.

5. Set Lomboz Java View, open window-> Customize perspective, as shown in Figure settings:


The next step is how to configure the Lomboz to work properly. In contrast to the installation process, the configuration process is not that simple, J. The Lomboz configuration steps are as follows:

1. Configure the JDK, select "Windows-> Preferences", select Lomboz, and configure the JDK. such as the legend:



2. Define the server, if your server is already included in the Lomboz default server list, this step can be skipped. The Lomboz default server list can be obtained by expanding the Lomboz in the previous step and selecting "Server Definitions" in it. The following is an example of adding Tomcat4.1.18 to show how to add a server. The relevant steps are as follows:

A) Enter the servers subdirectory of the Lomboz installation directory, copy a. server file (such as tomcat410.server) and rename it to Tomcat418.server.

b Open this file to change the following location of this file:

-<serverdefinition .../> change the value of name to a name you want (such as Apache Tomcat v4.1.8), which is used to display the server list portion of the "Server Definitions" interface;

-<property id= "serverrootdirectory" .../&gt, where the value of default is changed to the directory where Tomcat resides on your machine, such as D:/program files/java/ tomcat-4.1.18;

-<property id= "Classpathvariablename" .../>, where the value of default is changed to any name (such as TOMCAT418), which is used to represent the variable name of the Lomboz project's default Classpath ;

-<property id= "ClassPath" .../>, where the value of default is changed to the directory where Tomcat resides on your machine, such as D:/program files/java/tomcat-4.1.18;

c) Add Jasper-runtime.jar. By default, the Tomcatx.server file contains only 2 jar files: Servlet.jar and Bootstrap.jar, but Jasper-runtime.jar is missing. This jar file plays a very important role in the JSP debugging process, so please add it. There are two ways to add a jar to a server:

Method 1:

Add a row in the <serverClassPath> section of the. server file that you just edited: <jar type= "Variable" >${classpathvariablename}/common/lib/ jasper-runtime.jar</jar>;

Method 2: Use the "Server definitions" interface and do not repeat them here.

The configured server is displayed in the server definitions form, as shown in the following illustration:


Note: The tomcat4.x server needs to be patched to make the lomboz work properly, and the download address of the patch:

http://www.sysdeo.com/

Now that the Lomboz installation and configuration is complete, let's create a "Hello world!" Example to understand the Lomboz debugging JSP process it.

Debug JSP
Create a project
To debug a JSP using Lomboz, you must first create a Lomboz project. The steps are as follows:

1. Open File->new->lomboz Java project to create an item called debugjsp;

2. Select "Next" to enter the Lomboz Project Properties Selection page, add the Web module and the server used. Because our primary task is to debug the JSP, the EJB module can be empty. The following figure:


3. Select Finish,lomboz Project is created. At this point, the file structure generated by Lomboz is shown below:



Next, we can create the JSP file that we need. In this example I use the default index.jsp directly, and change its contents to:

<!--Copyright (c) 2002 by Objectlearn. All Rights Reserved. -->

<title>Welcome</title>
<body>
<center><%= "Hello world!" %></center>
</body>

So far, our preparation for debugging JSP is largely complete, but there are extra steps for people who use tomcat4.x (these steps are mainly caused by the tomcat4.x itself):

1. Add the following line to the Server.xml file in the Tomcat Config directory (see Server.xml related literature for specific locations):

<context path= "/testjsp" docbase= "d:debugjspdebugjsp" workdir= "d:debugjspj2srcorgapachejsp" >

Where path represents the URL name of the Web application; Docbase represents the physical location of the Web application; Workdir represents the location where the JSP corresponds to the Java file, you must create a directory structure and a name like orgapachejsp.

2. According to orgapachejsp in the corresponding J2SRC directory to create the corresponding subdirectory structure, while the J2SRC set as the project source directory.

Grammar check
Now, let's start to enjoy debugging the JSP process. The JSP should be free of syntax errors before debugging. Lomboz provides the functionality for JSP syntax checking, which is as follows:

1. Select the JSP file you want to check for syntax, and click the right mouse button.

2. Select Lomboz ee ...-> Check Jsp Syntax

Debugging
After solving the grammatical errors, the next step is to resolve the logic errors. For this kind of error can only be solved by debugging. The process of using Lomboz to debug a JSP is very similar to the debugging of a normal Java application, because its rationale is to use the server to generate JSP-corresponding Java files, and then debug them.

The steps for debugging a JSP are as follows:

1. Open Lomboz Java View, select the server, click the right mouse button to select "Debug Server". As shown in figure:



If the. server file is defined correctly, Tomcat will start. If you don't start Tomcat as you would expect, you'll be wrong in both ways: the Tomcat environment variable and the Lomboz server file.

2. Open the browser, such as IE, in the address bar input: http://127.0.0.1:8080/debugJsp/index.jsp. If there is no error in the JSP file syntax, the Java file corresponding to this JSP file will be generated in the j2srcorgapachejsp directory of the project. Re-refresh the project to see the files. As shown in figure:



This step is mainly to trigger the server based on JSP to generate debugging Java files, do not care too much about the results are correct. Because once Java files are generated, these errors can be excluded by debugging.

3. Open this Java file, set a breakpoint in it, and then enter the URL again in the IE Address bar, at which point the Eclipse Debug function is activated. At this point can be targeted to the JSP debugging, when the situation as shown:


As for the debugging of the object invoked by the JSP, after completing the preceding steps, then the corresponding Java



You can set breakpoints in the file.

Conclusion
Although the current JSP debugging is not easy to debug as normal Java file debugging, but the advent of lomboz such tools to at least end the manual debugging JSP phase. From this Java Web application developer does not have to stop the program from time to time to manually add print statements to observe the values of variables, instead, they can observe the changes of these values as well as debugging a normal Java application while the program is running. This greatly facilitates the development of web-based applications, reducing the time previously wasted for debugging.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.