Web Development with JavaServer Pages

Скачать в pdf «Web Development with JavaServer Pages»

Figure 15.6 Problem submission form


These headers indicate, among other things, that the request originated from version 4.5 of Netscape’s browser (nicknamed Mozilla), running on the Windows platform. The cookies correspond to the session ID code and the time stamp cookie associated with the JSP cookie example presented earlier in this chapter. Note that, as mentioned in the earlier discussion of the reportHeaders() method, only one of the two cookie headers appears among the header listings.

15.3 Mixing JSP and JavaScript


JSP can work in conjunction with JavaScript (and other client-side technologies) to add server-side processing to operations typically limited to client-side activities. As an example, we’ll build a simple form for reporting system problems. As an additional requirement, we’ve decided that we want to verify the validity of the host name specified by the user before allowing it to submit the problem. We also require that the problem host be identified by its IP address, rather than its host name. The resulting form is shown in figure 15.6.


When the user inputs a host name into the Affected System field of our form, it is changed into the corresponding IP address when they tab over to the next field. (If an actual IP address is supplied, it is not changed.) Furthermore, if the user inputs an invalid host name, an alert window will notify him or her of this fact and he or she will not be allowed to submit the form until the problem is corrected. All


of this happens on the client before submitting the form, and without the user having to manually reload the page. As a matter of fact, the form page, shown in listing 15.2, is not even a JSP page, it’s just standard HTML, with a little JavaScript thrown in. How, then, do we perform this little trick? We cheat.

Скачать в pdf «Web Development with JavaServer Pages»