Страница 1 из 1

Перегрузка HTML через аплет

Добавлено: 30 май 2005, 14:41
mobius
Как при помощи аплета заставить перегрузить страницу по другому URL?

Добавлено: 31 май 2005, 14:27
bulda
Редирект?
Вычитать страничу по другому URL и просто выкинуть ее в аплете?
наверное еще есть варианты.

Добавлено: 31 май 2005, 20:40
Deady
Отрывок из книги Core Servlets and JSP.

17 Using Applets As Servlet Front Ends
17.1 Sending Data with GET and Displaying the Resultant Page
The showDocument method instructs the browser to display a particular URL. Recall that you can transmit GET data to a servlet or CGI program by appending it to the program’s URL after a question mark (?). Thus, to send GET data from an applet, you simply need to append the data to the string from which the URL is built, then create the URL object and call showDocument in the normal manner. A basic template for doing this in applets follows, assuming that baseURL is a string representing the URL of the server-side program and that someData is the information to be sent with the request.

Код: Выделить всё

try {
   URL programURL = new URL(baseURL + "?" + someData);
   getAppletContext().showDocument(programURL);
} 
catch(MalformedURLException mue) { ... }
However, when data is sent by a browser, it is URL encoded, which means
that spaces are converted to plus signs (+) and nonalphanumeric characters into a percent sign (%) followed by the two hex digits representing that character, as discussed in Section 16.2 (The FORM Element). The preceding example assumes that someData has already been encoded properly and fails if it has not been. JDK 1.1 has a URLEncoder class with a static encode method that can perform this encoding. So, if an applet is contacting a server-side program that normally receives GET data from HTML forms, the applet needs to encode the value of each entry, but not the equal sign (=) between each entry
name and its value or the ampersand (&) between each name/value pair. So, you cannot necessarily simply call URLEncoder.encode(someData) but
instead need to selectively encode the value parts of each name/value pair. This could be accomplished as follows:

Код: Выделить всё

String someData =
   name1 + "=" + URLEncoder.encode(val1) + "&" +
   name2 + "=" + URLEncoder.encode(val2) + "&" +
   ...
   nameN + "=" + URLEncoder.encode(valN);
try {
   URL programURL = new URL(baseURL + "?" + someData);
   getAppletContext().showDocument(programURL);
} 
catch(MalformedURLException mue) { ... }
The following section gives a full-fledged example.

Добавлено: 01 июн 2005, 11:23
mobius
Спасибо всем