JBuilder2005 the landing page of the actual combat JSP

Source: Internet
Author: User
Tags html form html tags return dreamweaver stringbuffer
js| page file->new...->web-> Double-click the JSP icon to eject the Create JSP Wizard dialog box.
· Web module: If there is more than one Web module in a project, you can specify the Web modules to which the JSP will join, because there is only one webmodule in our project, so the wizard defaults to Webmodule.

· Name: Type the JSP filename, you can type the. jsp suffix, or you can type login directly without writing a suffix.

After the Generate sample bean option is checked, JBuilder generates an example bean and introduces the bean in the JSP. For starters, this option allows you to see how the JSP references a bean, and the Generate Error page option automatically creates a companion error-handling JSP file for the JSP, which we do not select.

Click Finish to create a login.jsp,login.jsp file appears in the compiler for the content pane.
The JSP compilation window has a vertical bar on both sides that can be controlled by and buttons, and the left column is a panel that places JSP tags and HTML tags, and can be dragged into the JSP file in the same way as the visual UI designer, as shown above, We select the HTML tab of the form from the panel and place it in the login.jsp file.

The right vertical bar is the property compiler for the label of the current cursor in the JSP file.

The property editor is dynamic, and the cursor moves to a different label, and the property editor displays all of the properties that the label can set. As the corresponding in the figure above is the HTML form tag's property editor, we set its Action property to switch.jsp, specifying that the request data be sent by post.

We provide a user name pull box, a password entry box, and a login submit button in login.jsp, with the following code:

Code Listing 4 login.jsp

1. <% @page contenttype= "text/html; CHARSET=GBK "%>
2. The
3. The
4.Login
5. The
6. 7. Form Name= "Form 1" method= "POST" action= "switch.jsp"
8. User name:9.--logged in user--BloomerBaoshu toothvertical teeth
14. Password: 16.
-
A.

A form label represents a form in a Web page, which can contain multiple components that are processed by a JSP file specified by the HTTP protocol to the action attribute when the Web page form is submitted. The form's data is typically sent as post, and post is sent in a way that has no limits on the amount of data and is more secure.


Practical experience:

The JSP file code contains both static and dynamic parts, that is, part of the HTML code, and the other part is the JSP tag and the Scriptlet code. JSP is generally dynamic logic of the Web page, JBuilder JSP tags and scriptlet These dynamic code part of the support is very good, you can use Codeinsight and taginsight tools such as fast and correct coding, but also can be compiled to debug JSP. In JSP static HTML code writing and visual design, JBuilder is powerless, Dreamweaver in static code and visual design is significantly better than JBuilder.

The complexity of things to promote the division of labor, the fine division of Labor to promote professional development, in the preparation of JSP, not once you have jbuilder have no request. Han Xinshan, Ho Hoshan, if you can combine Dreamweaver and JBuilder, with Dreamweaver development JSP visualization part, with JBuilder development JSP dynamic code part, both complementary have no, complement each other, JSP development work will become more flowing.

   Change the user list to dynamic

There is a flaw in the login.jsp currently created, assuming that when additional users are added to the database Background T_user table, because the user name pull box is static code, the newly created user does not appear on the page, so it is necessary to change the list of user names to dynamic code, using database tables T_ The user's record dynamically produces the data for the Drop-down box.

We do this through the Userlist.ava class, creating Userlist.java in the project, with the following code:

Code Listing 5 Userlist.java

1 package bookstore;
2. Import java.sql.*;
3.
4. Public class UserList
5.  {
6.//Get the user list code for the HTML drop-down box
7.   public static String getuserlisthtml () {
8. Connection conn = null;
9 StringBuffer sbuf = new StringBuffer ();   
. try {
11. conn = Dbconnection.getconnection ();    
PreparedStatement pStat = conn.preparestatement (
13. "Select User_id,user_name from T_user");
ResultSet rs = Pstat.executequery ();    
while (Rs.next ()) {
16.    Sbuf.append ("" +
17. Rs.getstring ("user_name") + "\ n");   
.}
19. return sbuf.tostring ();   
.} catch (SQLException ex) {
21. Ex.printstacktrace ();
Return "";   
.} finally {
24.    try {
25.     IF (conn!= null) {
26. Conn.close ();
conn = null;   
.}
29.  The catch (SQLException ex1) {
30. }
31.}
.}

Userlist.java only provides a static getuserlisthtml () method that obtains user records from the T_user table in the background database and generates the option code for the Select component of the HTML, as shown in line 16th to 17th.

After creating this class, we reference the class to adjust the login.jsp code, first referencing the UserList class through the Import property in the page instruction tag, and then adjusting the contents of the Select option to the value returned by the getuserlisthtml () method.
Replacing the original static HTML code with an expression label, it is worth mentioning that in the JSP you can also use Codeinsight input code as you would in writing a generic Java class. The adjusted login.jsp code is shown in bold, as follows:

Code Listing 6 Adjusted login.jsp code

1. <% @page contenttype= "text/html; CHARSET=GBK " import=" bookstore. UserList "%>
2. The
3. The
4.Login
5. The
6. 7. Form Name= "Form 1" method= "POST" action= "switch.jsp" > user name:
8. 9.--logged in user--<%=userlist.getuserlisthtml ()%>One.12. Password:14.
.

After saving the login.jsp, right-click in the content pane login.jsp File tab and select the Web Run using Defaults,jbuilder to start the Tomcat 5.0 application server and run on port 8080. Compile and run the login.jsp file.

JBuilder automatically switches to the Web View View page to show how the page works. However, the JBuilder browser's support for Web pages is weak and JavaScript scripting is not supported. So after running the login.jsp, it is best to view the effect of the Web page through IE, you only need to open IE, and the JBuilder access login.jsp address in the address bar can be copied.

The user in the Drop-down box for the user name is already in the dynamic list of users, and the user who is adding and removing users from the T_user table will change accordingly.

Before running the JSP, it is best to compile a separate JSP file: In the content pane of the JSP File tab right-click, in the pop-up menu select Make "xxx.jsp", you can complete the JSP file compilation, timely detection of errors. JSP files and Java files when editing, the biggest difference is that the Java program files in the editor and the structure pane are listed, but some errors in the JSP file need to compile to discover.

  Tips:

Since compiling a JSP file requires converting it to a servlet file, then compiling the intermediate servlet file, and then redirecting to the JSP file after the error occurs, compiling a JSP file is time-consuming and often takes several times longer than compiling a Java file. By default, compiling a project compiles all the JSP in the project and consumes a lot of time. So it's best to cancel the setup of the JSP file in the compilation project: properties...->build-> the check JSPs for errors at Build-time option in the Build Settings page by Project->project. Check this option when you really need it, and then cancel the option after compiling. This setting will allow you to gain valuable time for your development.


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.