Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Web Application Developer’s Guide phần 6 pptx
MIỄN PHÍ
Số trang
26
Kích thước
402.8 KB
Định dạng
PDF
Lượt xem
1456

Web Application Developer’s Guide phần 6 pptx

Nội dung xem thử

Mô tả chi tiết

Using InternetBeans Express 11-3

Using InternetBeans Express with servlets

Using InternetBeans Express with servlets

The InternetBeans Express components simplify both the display of live

data in a web page and posting of data from a web page into a database or

other data model.

Displaying live web pages with servlets using

InternetBeans Express

Most servlets should use an IxPageProducer component. This enables the

servlet to generate the entire response from a pre-designed web page,

inserting dynamic data as spans of text or in controls in a form on that

page. This has some advantages:

• You know what the response will look like. The page can contain

dummy data, which will be replaced.

• You can change that look by changing the page, without having to

touch the code.

For example, when using InternetBeans Express with a servlet, you can

open the servlet in the designer. A Database and QueryDataSet from the

DataExpress tab of the palette can provide the data for the servlet. You can

add an IxPageProducer from the InternetBeans tab of the palette. Set the

IxPageProducer’s htmlFile property to the file name of the pre-designed

IxPassword Represents a password field.

XHTML: <input type="password" />

IxPushButton Represents a client-side button.

XHTML: <input type="button" />

IxRadioButton Represents a radio button.

XHTML: <input type="radio" />

IxSubmitButton Represents a form submit button.

XHTML: <input type="submit" />

If the button that matches this component was the button

that submitted the form, the IxSubmitButton’s

submitPerformed() event fires.

IxTextArea Represents a text area.

XHTML: <textarea>

IxTextField Represents an input field.

XHTML: <input type="text" />

Component type Description

11-4 Web Application Developer ’ s Guide

Using InternetBeans Express with servlets

web page. When the servlet is run, the internal HtmlParser is invoked by

the IxPageProducer to locate all replaceable HTML controls.

The simplest way to replace HTML controls with controls containing

dynamically generated data is to use IxControls. You should add one

IxControl for each HTML control on the template page which will contain

data. Set each IxControl’s pageProducer property to the IxPageProducer. Set

the IxControl’s controlName property to match the name attribute of the

appropriate HTML control. Setting the dataSet and columnName properties of

the IxControl completes the data linkage.

The IxPageProducer.servletGet() method is the one you will normally call

to generate the page for display. This method should be called within the

servlet’s doGet() method. The body of a servlet’s doGet() method can often

be as simple as:

ixPageProducer1.servletGet(this, request, response);

This single call sets the content type of the response and renders the

dynamic page into the output stream writer from the response. Note that

the default content type of the response is HTML.

Internally, the IxPageProducer.render() method generates the dynamic

version of the page, replacing the controls that have an IxControl assigned

to them by asking the component to render, which generates equivalent

HTML with the data value filled in from the current row in the dataset.

You could call the render() method yourself, but it is simpler to call the

servletGet() method.

Some situations where you wouldn’t use an IxPageProducer in a servlet

include:

• When you don’t need the database session management and posting

features of the IxPageProducer and simply want the page template

engine, you can use the PageProducer instead.

• When you’re using specific individual components to render HTML.

For example, you can create an IxComboBox containing a list of countries,

and use it in a servlet with hand-coded HTML.

Remember that when using InternetBeans in a servlet, usually you should

use an IxPageProducer. When you are using IxControls, you must use an

IxPageProducer.

Posting data with servlets using InternetBeans Express

Processing an HTTP POST is simple with the IxPageProducer.servletPost()

method:

ixPageProducer1.servletPost(this, request, response);

Tải ngay đi em, còn do dự, trời tối mất!