Now eclipse is getting better and better. With the release of Sun jdk5.0 patch 4, eclipse3.1 is also officially released, The combination of the two is much faster than before. However, it may take some time for wtp0.7 M5 to be released. At the end of this month, wtp0.7 may have a release. Now the two are basically mature, It is very convenient to use eclipse + WTP to develop JSP But there are not many articles on the configuration and use of WTP plug-ins. Many people think that WTP is too troublesome, I have been using WTP to develop JSP. I often ask related questions. So I wrote this article to introduce WTP configuration and the process of developing JSP. The configuration and development in the jdk5.0b4 + eclipse3.1 + wtp0.7m5 environment are introduced here, Other versions have minor differences, but the main process is the same. 1. Download and install this is of course the first step, here is the connection: http://www.eclipse.org/webtools/index.html 2. Configuration
There are many items to be configured, as shown below: 1) Configure Java-buildpath
2) JDK is required when jdktomcat is configured to run, and JRE is automatically found in eclipse, for example:
3) configuration XML and Internet cache usually have many XML files in Web applications. By default, WTP will verify these XML files, this requires the definition of DTD or XSD files for these XML files. By default, WTP automatically downloads and caches the files for future use. Therefore, we need to enable the cache function first. See. just remove the disable cashing check.
You can also configure definition files of common XML files in xmlcatalog. These files are automatically used for XML verification. For details, see:
No. You can only remove the XML automatic verification. For details, see the validation option. 4) configure the Tomcat server. Now we will configure tomcat. The configurations of other servers are roughly the same, as shown in:
Enter the Tomcat path and JDK
3. To develop a JSP, first create a dynamic web project. After confirmation, the system will prompt whether to enter the J2EE perspective. If yes, enter the Java perspective. For example: (Note: if the previous version is used, the dynamic web project may not be found at the time of new, but there is a flexible project. Create a flexible project first, and then create a dynamic web project under this project !) Note: during the first running, WTP needs to verify the Web. xml file, so it will download the DTD or XSD used for Web. xml verification, so the speed is slow,
Wait patiently and wait until all the required files are downloaded.
After the project is created, create a Java class and a JSP file below. For example, pay attention to the directory structure:
The Java class and JSP in the figure above have been created. Now we test this JSP page in Tomcat, right-click the webtests project, and there is a run on server in the menu, click it and select the server dialog box. Select the created Tomcat server, add the project, and finish. WTP opens a browser in eclipse to open the project. Note that WTP automatically creates and opens the project servers. This project is required to test the JSP page under Tomcat and must be in the open state. Otherwise, JSP testing cannot be conducted. 4. troubleshooting of Common Problems 1) No server error in some versions of WTP, It is a dialog box with a Red Cross, saying no server. At this time, please confirm that the servers project has been opened. 2) Class undefined errors if you use some external jar files in the web project, such as log4j, you may have added this jar in the classpath of the project, but the runtime will not find the class because the jar is not copied to the project's deployment directory under the WEB-INF/lib directory, display the navigator view, as shown in. ". Deployables" is the place where a web project is deployed. Copy the jar to Lib. (Another solution is to copy the jar to the/webtests/webcontent/WEB-INF/lib directory, but there is a drawback to doing so, it is troublesome to view the class source code in the package you are using. My practice is to configure frequently-used packages to the user library, set the source code, and then add it to the classpath of the project. If you copy the JAR file to the/webtests/webcontent/WEB-INF/lib directory, then there are two identical packages in the classpath of the webtests project, select when viewing the source code, and will take the/WEB-INF/lib package as the priority, which may be related to the Order in classpath, but not convenient. Therefore, you can directly copy the JAR file to the. deployables directory to solve this problem. We hope this problem can be solved in WTP later versions. If you can automatically copy all the jar files set in classpath to the. deployables directory, it will be convenient .) 3) if the context is incorrect, there may be a context error. There are roughly two types: one is a duplicate context error. In this case, Tomcat cannot be started. In the servers project, manually delete the duplicate context entries in server. xml. Another error is "no context". Tomcat can be started at this time, but the page cannot be found in the browser, which means server. the context does not exist in XML. The solution is to delete the server in the servers explorer view and re-Add the web application. Sometimes, you can reconfigure the server. If you have any questions, please write an email to discuss it with me.
|