Develop web applications with JBuilderx

xiaoxiao2021-03-06  43

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:

The login page accepts the user ID and password entered by the user, submits to the Execute.jsp page processing, let's write execute.jsp: file-> new ...-> Select Web-> in the tree on the left of the Object Gallery window Double-click the JavaServer Page icon in the right window to pop up the following dialog:

Figure 9. JSP page

Type the name of the JSP page in the name in the dialog: Execute, click Next, click Next, click Next, enter the Wizard Step 3, in this step, allow you to set the page reference JavaBean: Figure 10 . Set JAVABean from the JSP page

After clicking OK, the LoginPro.Userbean class is defined as a JavaBean of the page, and its ID default is bean0, we change it to the userbean, and you also allow you to specify this JavaBean scope, we choose Session. Click Finish to get the code of the execute.jsp file:

<% @ Page ContentType = "Text / HTML; Charset = GBK"%> Execute </ title> </ head> <jsp: usebean id = "userbean" scope = "session" Class = "LoginPro.userbean" /> <jsp: setProperty name = "Userbean" Property = "*" /> <body bgcolor = "# fff"> </ body> </ html></p> <p>It is necessary to point out the <JSP: setProperty Name = "Userbean" Property = "*" /> The parameter value sent by the client is received in the way, here, when login.htm is submitted, Userbean's UserID and Password two A value that will be set to two input boxes in the login.htm page form.</p> <p>After receiving the value of the client, the program compares the record in the T_User table in the database to identify whether it is a legitimate user, now we add code to Execute.jsp, complete these processing:</p> <p><% @ Page ContentType = "Text / HTML; Charset = GBK" ErrorPage = "Error.jsp"%> <% @ page import = "java.sql. *"%> <% @ Page import = "loginpro.dsbean" %> <Html> <head> ... <jsp: setproperty name = "userbean" proty = "*" /> <body bgcolor = "# fff"> <% connection conn = dsbean.getConnection (); string sqlstr = "select count (*) from T_USER where USER_ID = and password =??"; PreparedStatement pStat = conn.prepareStatement (sqlStr); pStat.setString (1, userBean.getUserID ()); pStat.setString (2, userBean.getPassword ()); ResultSet RS = PStat.executeQuery (); if (rs.next () && ration (1) == 1) Out.print ("You are a legitimate user, welcome you!"); Else Out.print ("Password is not right, or you have not registered as a system"));%> <body bgcolor = "# ffffff"> We just simply send usrid and password's value to the database Comparison, in the real application, must check if the value of userid and password is single quotation number (') in advance, if there is, it must be converted into two single quotes (' '), otherwise the security vulnerability problem will be generated, Interest friends can find relevant information online.</p> <p>The last JSP is an error.jsp that handles errors and exceptions, and its code is as follows:</p> <p><% @ Page ContentType = "Text / HTML; Charset = GBK" iSerrorPage = "true"%> <% @ page import = "java.sql.sqlexception"%> <html> <head> <title> error </ title > </ Head> <body bgcolor = "# ffffff"> <% if (Exception InstanceOf Sqlexception Out.println ("Database Operation Exception, Contact System Administrator Contact"); Else Out.println ("happened Unknown exception, please contact the system administrator ");%> </ body> </ html> When the execute.jsp discovers the database operation or other exception, it will jump to the error handling page, print out Readiness is strong.</p> <p>Since JBuilderx is not strong for page visualization, you can do the development of HTML and JSP visual content in Dreamweaver, and complete the development of the logical processing section in JBuilderx, after all, this world will always need collaboration.</p> <p>To run the web program in JBuilderx, we have completed the development of all programs in the project. Here we will run the web program in JBUILDERX. Before running the program, you must have a web server already set. Project-> Project Properties ...-> Set Server in the left tree on the pop-up:</p> <p>Select Tomcat4.1 in the Single Server for All Services in Project option, the default settings are Tomcat 4.0. If you configure other web servers to JBuilderx, such as WebSphere or WebLogic, they are listed in this drop-down box. However, I will not discuss this, a main reason is that although JBuilderX allows you to set and run these services in the development environment, it takes a long time to test due to these heavyweight web services on or off. Brought a lot of inconvenience. So our general practice is to complete the test in a lightweight web service (generally in Tomcat), and deploy it to the real enterprise web server. Further, we will not run the Tomcat test in JBuilderx, but through the external Tomcat, it will be inconvenient to change the changes when the JBuilderX is turned on. About Tomcat Configuration Discussion has exceeded the scope of this article, interested friends can study themselves. For the sake of simplicity, this article will complete the test in the JBUILDERX environment. Right to the Login.htm tab in the edit window, select Web Run for "Execute":</p> <p>Figure 11. Running Web Services</p> <p>JBuilderX will automatically complete the settings of web configuration information and start the web service at the 8080 port, and the login.htm login page is displayed to accept the user's entry, we log in to zhangshang / 123456:</p> <p>Figure 12. User login</p> <p>If the database has not started yet, execute.jsp goes to Error.jsp, the error page outputs the following:</p> <p>Figure 13. Error page</p> <p>After ensuring the database start and the connection is normal, you will get the correct login page: Figure 14. Login successful page</p> <p>You can also start IE, type the correct address to run the program in the address bar of IE.</p> <p>Some common problems works in using the JBuilderx development project, you may encounter some small trouble, here I will introduce two commonly influential developer emotions and their solutions. 1. The editing interface does not support Chinese: The Chinese you typed in the editing interface will become a string of unrecognizable "mouth mouth". This problem is like only in the JBuilderx version, but it will not be in each machine. It happened. Once, JBuilder in my colleague had happened, and later I helped him change the JBuilderx configuration file c: / documents and settings / administrator / .primetimex / user_zh.Properties settled this in order to solve this Question, specific solution, you can refer to this article in the Borland website. 2, the cursor misplaced: This problem is a tutty of the JBuilder development tool, and each JBuilder version has this problem (Borland's disabled, the spirit of the unswerving, let me wonder, and also admire). The solution is simple. For a low version of JBuilder, you may set the font to the Song, but in JBuilderx, the font selection pull-down boxes list only two fonts: Courier New and Lucida Sans Typewriter, no Song, this It is a bug. But we may be able to save the country through other methods: Tools-> Perferences ...-> Click on the Color on the left of the pop-up window listing the writing style of Java, HTML / XML, JSP, and other format files in the setting interface of the left window. Remove all bold formats:</p> <p>Figure 15. Setting up code format</p> <p>As shown in Figure 15, you can select a coarse statement in the edit box in the lower right corner of the interface, and then cancel the box of the BOLD check box. This has no problem with the misalignment of the cursor. Summary The reason why JBuilder is so popular is obvious. Borland as developers and database tool suppliers are extremely prominent as developers and database tool suppliers due to their code editing. Borland dominates the IDE market. Research on JavaPro and DEVX show that JBuilder has always been the most common use of Java developers and greatly exceeds the adoption rate of other similar products. This article develops a simple example as the main line, introduces you all aspects of the JBuilderx development web project, and points out some of the actual experience and some common problems in the development. It is recommended that you have repeatedly developed this example in the JBuilderx environment after reading this article, after all, the paper is full, and we must do it.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-71868.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="71868" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.036</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '38YMe3pLs4sbu_2FbE_2Fm8_2FWb53Ule3Eti5XECvXNVMS7nGpZYkq9jGiM6NhlrQhDnDRv3M8JeG61j2ajZsKiWiow_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>