Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Ngoài ra, một người dùng nhập vào giá trị có thể xác định màu nền của servlet. Các servlet trong Chương 7, "Hướng dẫn: Tạo một servlet đơn giản" sử dụng một tham số của kiểu String để cho phép nhập tên của người dùng. Tên tham số trong file shtml là UserName, biến tương ứng, được sử dụng trong servlet java tập tin là userName. | Step 6 Creating the data connection to the DBServlet 7 Click the Test Query button to test the query. If the query is successful the word Success displays to the right of the button. If the query cannot be executed an error message attempts to explain why the query failed. 8 Click OK to close the Query dialog box. 9 Click the Source tab to switch back to the editor. Note You may see the following message displayed in the Designer tab of the message pane Failed to create live instance for variable myDM guestbookservlet.DataModulel For now you can ignore this message. You ll fix this in a later step. Right-click the Designer tab at the bottom of the AppBrowser and choose Remove Designer Tab to remove the tab. 0 10 Click the Save All icon on the toolbar to save your work. JBuilder adds the queryDataSet1.setQuery method to the jbInit method. In the next step you ll set up the data connection to the DBServlet. Step 6 Creating the data connection to the DBServlet In this step you ll create a data connection to the DBServlet. The connection allows the servlet to pass data to the data module. 1 Double-click DBServlet.java in the project pane to open it in the editor. 2 Find the line of code in the class definition that reads private static final String CONTENT_TYPE text html 3 Position the cursor after this line of code and add the following line of code DataModule1 dm guestbookservlet.DataModule1.getDataModule 4 Click the Save All icon on the toolbar to save your work. Now that the servlet is connected to the data module you need to make both servlets and the data module do something. From this point on in our tutorial you ll be entering code directly into the editor. The first step will be to create an input form in FormServlet. Step 7 Adding an input form to FormServlet In this step you ll add code to the doGet method of FormServlet. This code creates a form using the HTML form tag. The form reads in two values - UserName and UserComment - entered by the user. This data