This article will lead you a simple Web project to enable you quickly enter JBuilderx's Hall Borland's JBuilder is the world's leading Java development environment. The latest version of JBuilderx is a comprehensive cross-platform environment for developing enterprise Java applications. It has added a lot of new features in a revitalization of JBuilder, which has become the most powerful Java visual development environment. This article will pass a simple Web project to enable you quickly enter the Hall of JBuilderx. JBuilderx's function is extremely rich. This article will not introduce all the features in this article, and will only introduce some of the functions involving example project development, and will introduce some common functions. Or not mention, I believe you can naturally grasp those basic functions during the project development operation. You can also understand and master these contents through JBuilderx online help documents, recommend you to read the top 4 basic tutors in help-> jbuilder Toturials. Project introduction Although JBuilderX can be used to develop applications such as desktops, wireless, Applets, but more than 80% of users use it to develop J2EE's web applications, so I have designed a simple web application project, and you will also lead you to development. A web application that can be run. This web project contains only one user login function, and its system block diagram is as follows:
Figure 1. System block diagram
Where web application servers are Tomcat4.1, the database server is Oracle10g. This item includes the following: 1) User table t_user: Information for saving users 2) Login page login.htm: Let users enter Username and Password 3) User Information JavaBean class UserBean: Include three properties, ie user ID and users Password and Username 4) Get Database Connection Class DSBean: Get Database Links to Operation Database 5) User Login Process Page Execute.jsp: Comparison of User ID, User Password, and Database 6) Exception Processing Page Error .jsp: When the abnormality is transferred to an exception handling page, the collaboration relationship between the parties in the humanized error message project is shown below:
Figure 2. Collaboration relationships of each part in the system
Creating a database first logged in the Oracle database with the System user, create a database user:
Create User Test Identified by Test; Grant Connect, Resource To Test
User Information Table T_User, which includes three fields, the structure of which is as follows:
Field name Type Note User_id varchar2 (10) User IDUSER_NAME VARCHAR2 (20) User Name Password Varchar2 (30) User Password
Log in to the database, run the following statement SQL, create a user information table:
Create Table T_User (user_id varcha2 (10) Primary Key, User_Name Varchar2 (20), Password Varchar2 (30)) /
Insert two user information in the table:
INSERT INTO T_USER VALUES ('zhangshang', 'Zhang 3', '123456'); INSERT INTO T_USER VALUES ('Lisi', 'Li Si', 'ABC'); commit;
Create project project
Create a project: file-> new project The following interface appears:
Figure 3. Creating a project engineering
The item is named loginpro, placed in the D: / LoginPro path, and you can press next to NEXT. After creating a project project, create a web module under the project: file-> new ...-> Left tree Select Web-> Double-click the Web Module (WAR) item of the right window -> Click Create Empty in the pop-up window Web module, press Next-> Press the following settings in the pop-up:
Figure 4. Setting the web module path and technical standards
The name of the web module is loginweb, placed in the LoginWeb subfolder under the project path, sets the version of Servlet and JSP. Click Finish directly to complete the creation of the web module after you are finished.
Special reminder reader, if you develop a web project, you must create a web module. Only in this way, Java classes developed in the project After Rebuild, JBuilderx will call the Ant tool, and synchronize the compiled Class file to the web module In the web-inf directory. The author once had a friend who complained to me. It was very troublesome to use the JBuilder development web program. He didn't create a web module in the project. After changing the class, he will handle the compiled classes to the web application Web. Under the -inf / classes directory, I don't know that Jin Guang Avenue has been opened, but it is still struggling in the sheep trail.
Two classes include two classes in writing, one is user information class UserBean.java, and the other is to get database connection class dsbean.java. Let's write these two classes:
First write UserBean.java classes: file-> new class ... pop up the following window:
Figure 5. Writing class wizard
Enter a class Userbean on the window interface of the class wizard. The name is the name of the project. You can change the names of the other meaningful package, and we simply accept the default package name. After pressing OK, get the following class code in the editing window:
Package loginpro; public class userbean {public userbean () {}}
Below we add 3 properties to the Userbean class: Click the BEAN tab at the bottom of the userbean -> Select the sub-tab of the Properties under the bean tab -> Add the class by add print by addprty, click on the Button Bounce Properties Window -> Add attributes in this window.
However, the author believes that the method of this conventionally adding attribute is relatively awkward, the efficiency is very low, you can switch directly to the Properties tab by typing the global variable in the class, then switch to the Properties tab, JBuilderX will automatically list the global variable column In this page, by hooking the check box in the Getter and Setter columns, the variable SET and GET methods are automatically generated, and the author chooses this method when writing a program. After adding global variables, the Userbean code is as follows (where bold is red, the same below):
Package loginpro; public class userbean {private string userid; private string password; public userbean () {}}
Switch to the Properties page, check all getTER and SETTER
After switching back to the code page, the GET and SET methods of the attribute are automatically generated:
... public class UserBean {... public String getPassword () {return password;} public String getUserID () {return userID;} public String getUserName () {return userName;} public void setUserName (String userName) {this. userName = userName;} public void setUserID (String userID) {this.userID = userID;} public void setPassword (String password) {this.password = password;}} after writing a good UserBean let us write data acquired DSBean connection, in Before writing this class, because the class needs to use the Oracle JDBC package, we need to load the Oracle JDBC's JAR package to the class library, and introduce it into the project engineering.
The latest version of Oracle is Oracle10G, if you have Oracle10g installed, the JDBC package is in [Oracle_home] /jdbc/lib/classes12.jar, if you do not arrange the database, you can go
Download the JDBC driver here, it is compatible down. Suppose we have downloaded them to the D: / extra directory, we load them into the JBuilderx library: Tools-> Click Configure Libraries to pop up the Configure Libraries window, as shown in Figure 6, first click on the CONFIGURE LIBRARIES window. New ... popped up the New Library Wizard window, take a name to this class in the window called jdbclib, then click the Add ... button to pop up the Select One or more Directories window, position to the D: / extra directory, select Class12.jar, then confirm it.
Figure 6. Add new class to the JBuilderx class library
Next we need to reference this new JAR package in the project in the project, so that the project can access this JDBC's JAR package: Project-> Project Properties Select Paths in the tree on the left of the pop-up window, follow the operations of Figure 7 Quote Task:
Figure 7. JAR package to add JDBC to the project
It should be pointed out that if the project needs to reference a large number of external JAR packages, these JAR package can be organized into a directory, then add the entire directory to the class library, reference to the library name corresponding to the directory in the project project. Call these packages in the project. When the Rebuild project, JBuilderx will synchronize these packets into the directory of the web application.
Everything is ready, we start writing dsbean.java:
package loginpro; import java.sql *;. public class DSBean {public static Connection getConnection () throws SQLException {try {Class.forName ( "oracle.jdbc.driver.OracleDriver");} catch (ClassNotFoundException ex) {System.out .println ("Database driver is not found.");} Return DriverManager.getConnection ("JDBC: Oracle: Thin: @ 192.168.0.189: 1521: Ora9i", "Test", "Test");}} My database On the machine IP is 192.168.0.189, the SID of the database is ORA9I, and the reader must change according to the specific situation of your database when writing.
After writing these two classes, we can right-click LoginPro.jpx in the Project Engineering panel, select Rebuild to compile these two classes. After compiling the class, the class will not only output it to the D: / loginpro / class content, at the same time It will also be synchronized to the D: / LoginPro / LoginWeb / Web-INF / CLASS directory, and the external package referenced in the project will be copied to the D: / LoginPro / LoginWeb / Web-INF / LIB directory. It is worth noting that if you use the make command to compile, the class will only be output to D: / LoginPro / Classes without synchronizing to the D: / loginpro / loginweb / web-inf / class directory. Discussion on the web directory structure of J2EE beyond the content of this article, please read the relevant information yourself.
Log in to page and processing page
Write the user login page login.htm: file-> new file ... Bounce the following dialog:
Figure 8. Create login.htm
Type the page code below in the Edit window: