Java Reference
In-Depth Information
9.
Save the source code and run MyServlet on the RAD server.
The browser should look like Figure 8-21 . If it doesn't, click the refresh button.
Figure 8-21.
10.
In the browser's address field, replace MyServlet with Howdy.html and press Enter.
The Howdy page will be displayed.
11.
In the browser's address field, replace Howdy.html with MyServlet and press Enter.
The browser should again look like Figure 8-21 . Notice that you were able to run the servlet from the browser.
The point being: browsers can be used to access more than just Web pages and, as described, the application server
finds and executes class files, and then sends the response back to the browser. In addition, notice that the file
extension (.class) did not have to be specified in the servlet's URL. (With most Web pages, the extension .html
must be included.)
Of course, using servlets to display static text is way too much work for the programmer. Simple Web pages can
do this with much less effort. However, retrieving user-specified information and then displaying it would be worthy
of a servlet.
Tutorial: Defining Form Components
To retrieve user information, we will create a form for data entry and then code the servlet's doPost method to retrieve
and display the information.
1.
In the Enterprise Explorer pane, click on TutorialsWeb project to select it.
To create a file to hold the form, click File , New , and then Other .
2.
3.
On the New window, expand the Web item, select Web Page, and click the Next button.
4.
On the New Web Page window, select HTML/XHTML, specify EnterEmpInfoForm as the
File Name, and click the Finish button.
A blank page will be displayed in the Split view. We will use the Design view's GUI to build the Web page this time
instead of typing the HTML code.
 
Search WWH ::




Custom Search