Debug JSP using Lomboz
Ube bun (james.hu@chinacodeline.com)
Xi'an Software Co., Ltd.
September 2003
Foreword
Anyone who has JSP written experience has a hard experience in JSP debugging. Since the lack of automated debugging tools makes a lot of print statements that have to be used in the file when debugging JSP. This approach is a simple and effective means for the location of the JSP range, but how to quickly and efficiently position the internal error of the object called in the JSP. It is a bit unhappy. Because this will have to compile, release, start and stop the server, bringing great inconvenience to debugging.
The Legend of the JSP debugging tools you have obtained, don't exist on the situation currently mastering. If the reader has the hope of this information, huh, huh. But JSP debugging tools do exist, and it is free! IT's Lomboz. Download address: http://www.objectLearn.com/products/download.jsp
From a simple example, this paper describes how to use Lomboz to debug JSP. The development environment of this example is as follows:
- JDK version: 1.4.1;
- Java Ide: Eclipse 2.1;
- Lomboz: Suitable for plugins for Eclipse2.1;
- JSP / servlet container: Tomcat 4.1.18.
Introduction to Lomboz
Strictly said that Lomboz is a J2EE plugin for Eclipse. It integrates many Java application servers, J2EE components, and web applications to Eclipse, which can help Java developers use Eclipse to build, test, deploy J2EE applications. For the focus of this article, JSP debugging, it also has related support:
- Support JSP writing, including: syntax coloring and syntax check;
- Support JSP debugging.
For JSP debugging, the principle of Lomboz is to debug the Java code generated by the JSP page to be debugged. The entire debugging process is the same as the debugging process of the Java application, whether it is a JSP itself debugging or a debugging of the object called by JSP, it is seamlessly coupled to a piece.
Before you begin this article, let's first look at the Lomboz installation and configures for normal use of its JSP debugging.
Installation and configuration
Lomboz installation process is very simple, and the plugin installation process of Eclipse 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 the Eclipse has run, then turn it off first.
3. Extract the downloaded file to the plugins directory in the Eclipse installation directory.
4. Restart Eclipse to open "About Eclipse Platform Plug-Ins" (Help -> About Eclipse Platform -> Plug-in Details), if the Lomboz installation will appear information about it. As shown below:
Note: If you want to remove Lomboz, you only need to delete the directory of the PLUGINS directory.
5. Set the Lomboz J2EE View, open Window -> Customize Perspective, as shown in Figure Set:
The next is how to configure Lomboz to make it work. Contrary to the installation process, the configuration process is not that simple, J. The Lomboz configuration steps are as follows:
1. Configure JDK, select "Windows -> Preferences", select Lomboz, and configure the JDK. This is as follows:
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 Lomboz in the previous interface, then select "Server Definitions". The following is to add Tomcat4.1.18 as an example to show how to add a server. The relevant steps are as follows:
a) Enter the servers subdirector of the Lomboz installation directory, copy one .server file (such as Tomcat410.server) and rename it to tomcat418.server.
b) Open this file to change the following location of this file:
-
-
-
-
c) Add Jasper-Runtime.jar. By default, only 2 JAR files are included in the Tomcatx.Server file: servlet.jar and bootstrap.jar, but lack jasper-runtime.jar. And this JAR file has played a very important role in JSP debugging, so please add it. There are two ways to add JAR to a server:
method 1:
Add a line in the
Method 2: Use the "Server Definitions" interface, no more details here.
Configured servers are displayed in the "Server Definitions" form, as shown below:
Note: For Tomcat4.x servers, you need to put patch to make Lomboz work, patch download address:
http://www.sysdeo.com/
At this point, Lomboz installation and configuration has all been completed, let us create an example of "Hello World!" To experience the process of lomboz debugging JSP. Debug JSP
Create project
To use Lomboz debugging JSP, you must first create a Lomboz project. Proceed as follows:
1. Open File-> New-> Lomboz J2EE Project, create a project called debugjsp;
2. Select "Next" to enter the Lomboz Engineering Properties Select page, add web modules and servers used. Since our main task is to debug JSP, the EJB module can be empty. As shown below:
3. Choose Finish, Lomboz project is created. At this point, the file structure generated by Lomboz is shown below:
Next, we can create the JSP file you need. In this example I use the default index.jsp, change its content to:
hEAD>
body>
html>
As far as it is, we debug JSP preparation is roughly completed, but the person who uses Tomcat4.x needs excess steps (these steps are mainly caused by Tomcat4.x itself):
1. Add a lower line in the server.xml file in Tomcat's config directory (see Server.xml):
Among them, PATH represents the URL name of the web application; DOCBASE represents the physical location of the web application; Workdir represents the location of the JAVA file corresponding to the JSP, must create the directory structure and name of ORG / Apache / JSP.
2. Create a corresponding subditio structure in the corresponding J2SRC directory, and set the J2SRC as the Source directory of the J2SRC.
Syntax check
Now let's start enjoying the process of debugging JSP. The JSP should be no syntax error before debugging. Lomboz provides the function of JSP syntax check, and the specific operation is:
1. Select the JSP file you want to perform syntax check, click the right mouse button;
2. Select Lomboz J2EE ... -> Check Jsp Syntax
debugging
After solving the synergistic error, the next step is to solve the logical error. This error can only be solved by debugging. Using the Lomboz debugging process is very similar to the debugging of a normal Java application, because its principle is to use the server to generate a JAVA file corresponding to the JSP, and then debug them.
The steps to debug JSP are as follows:
1. Open the Lomboz J2EE View, select the server, click the right mouse button to select "Debug Server". As shown in: If the .server file is defined correctly, Tomcat will start. If you don't start Tomcat as expected, then troubleshoot from these two aspects: Tomcat environment variables and Lomboz Server files.
2. Open the browser, such as IE, enter: http://127.0.0.1: 8080 / debugjsp / index.jsp. If the JSP file syntax does not have an error, the JAVA file corresponding to this JSP file will be generated in the J2SRC / ORG / APACHE / JSP directory. Refresh the project to see these files. Figure:
This step is mainly to trigger the server based on JSP's Java files that can be debugged, do not have to be precise. Because once the Java file is generated, these errors can be excluded by debugging.
3. Open this Java file, set the breakpoint in it, then enter this URL again in the address bar of the IE. At this time, the Eclipse debugging function is activated. At this point, JSP can be commissioned, and the situation is as follows:
As for the debugging of the object called the JSP, after completing the above steps, then set the breakpoint in the Java file corresponding to the object.
Conclude
Although the current JSP debugging is not convenient to be as convenient to regular Java file, the appearance of the Tomboz tool has at least the stage of manual debugging JSP. Since this Java's web application developer does not have to stop the program from time to time to manually add a printed statement to observe the value of the variable, the opposite can observe the changes in the program while debugging the normal Java app. This greatly facilitates the development of web applications, which reduces the time to be wasted for debugging.
Reference
l Jiang Yan's "Using Eclipse Development J2EE Application" introduced how to develop J2EE applications using Lomboz;
l Lomboz Official Website www.objectLearn.com, there is a documentation and related tutorials on Lomboz;
l Eclipse's official website www.eclipse.org;
l Eclipse In Action, a good book on eclipse in an extraction;
L Tomcat's official website http://jakarta.apache.org/tomcat/index.html;
About author
Hulu, Master of Engineering, Xi'an Jiaotong University, is keen on J2EE / .NET technology, is the loyal advocator of OpenSource. At present, Xi'an Software Co., Ltd. is currently created with friends. The company is mainly committed to the development of Java web applications, and many projects have been applied in energy, electricity and transportation industries. You can contact him through James.hu@chinacodeline.com.