1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Servers and Applets + Form ppsx

34 277 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 34
Dung lượng 781,94 KB

Nội dung

Servers and Applets + Form GV: Vũ Đình Hồng Khoa: CNTT – TỨD  •   !" • #$%%#&'( #) • *+, #+#/0/,,#1/#2 ##//+#+-#3##/%%#+/ +##+ • 4#(54///%,#++# #++3#/%%#&'(#) • 6!%/++#'(+##/,## /,#7 8 • '/%%#2 +,3,9# • *:;<=>9?, !@ *:;%,/9*:;A #3 *:;&-/+#*:;  B CDC  B +,9#//)E #$%%#,#1&)"+,3,9#&%,/9*:;)E F/&G/H,9#*:;1#%,9#)@"""FE 4+,9#//A /9#IBCACB*:;,#"#,#&/I)BCJCB/9#KB CACB*:;,#"#,#&/K)BCJCB /9#BCACB*:;,#"#,#&/)E LMNO$%%# public class Search Applet extend Applets implements ActionListeners { public void actionPerformed (ActionEvent event) { String query = URLEncoder.encode(queryField.getText()); SearchSpec[] commonSpecs = SearchSpec.getCommonSpecs(); for(int i=0; i<commonSpecs.length-1; i++) { try { SearchSpec spec = commonSpecs[i]; URL searchURL = new URL(spec.makeURL(query, "10")); String frameName = "results" + i; getAppletContext().showDocument(searchURL, frameName); } catch(MalformedURLException mue) {} } } }  LMNO*!/++ public class SearchSpec { private String name, baseURL, numResultsSuffix; private static SearchSpec[] commonSpecs = { new SearchSpec(“google”,”http://www.google.com/search?q=“, ”&num=“),…}; public String makeURL(String searchString, String numResults) { return(baseURL + searchString + numResultsSuffix + numResults); } … }  LMNO'G;P# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN"> <HTML> <HEAD> <TITLE>Parallel Search Engine Results</TITLE> </HEAD> <FRAMESET ROWS="120,*"> <FRAME SRC="SearchAppletFrame.html" SCROLLING="NO"> <FRAMESET COLS="*,*,*"> <FRAME SRC="GoogleResultsFrame.html" NAME="results0"> <FRAME SRC="InfoseekResultsFrame.html" NAME="results1"> <FRAME SRC="LycosResultsFrame.html" NAME="results2"> </FRAMESET> </FRAMESET> #:##+OQ/ :#+ '(# • Ý tưởng – GR9S+,#<TUV+## /,%W/'( • Thuận lợi – /,%W/H#3/ – =X 4##2+#YZ8 [W%I'G;<Z!<\ • Bất lợi – ,]^^!_9/`<]+##9/_=_<,]/] <=X`,/ – $%%#[W% ![a<=> %b • 7Wc'G; '(#/ :##++ • /`,I<W]=X`<_d`%<]*:;9/]!^^//%%# URL dataURL = new URL(…); • /`,I<W]=X*:;,#, URLConnection connection = DataURL.openConnection(); • '=X]de/]_!`W=/]=e`*:; connection.setUseCaches(false); • ]d`%-d]_/]<_'G;9,9W] • ]d`%/]W_=e`<d_/_, – ,` connection.getInputStreamE-/,-,`-X^/]Wd]%/,X • f,`=e`<=X`=^=_+## – L]`[,`readLine  BufferedReader • f,]/]W_=e`<d_/_, '(##9%/#O #4# URL currentPage = getCodeBase(); String protocol = currentPage.getProtocol(); String host = currentPage.getHost(); int port = currentPage.getPort(); String urlSuffix = "/servlet/SomeServlet"; URL dataURL = new URL(protocol, host, port, urlSuffix); URLConnection connection = dataURL.getConnection(); connection.setUseCaches(false); connection.setRequestProperty("header", "value"); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = in.readLine()) != null) { doSomethingWith(line); } in.close();  [...]... Objects) • Truyền dữ liệu với Post and UrlConnection Ghi Chú (tt) – Chỉ có thể truy cập URLs trên applet’s home host – Dùng Applet để xem kết quả – Applet có thể gửi những dữ liệu phức tạp (bao gồm cả Java Object) – Máy chủ cũng có thể gửi những dữ liệu phức tạp (bao gồm cả Java Object) • Bypassing Web Server Form Element • HTML Element: • < /FORM> • Attributes: – ACTION (required),... tường lửa – Cần phải chạy thêm một máy chủ khác Ghi Chú • Truyền dữ liệu qua Get and showDocument – Có thể truy cập ở bất cứ url nào – Dùng trình duyệt để xem kết quả • Truyền dữ liệu qua Get and URLConnection – Chỉ có thể truy cập URLs trên applet’s home host – Dùng applet để xem kết quả Ghi Chú (tt) • Truyền dữ liệu qua Get and URLConnection (tt) – Applet chỉ có thể gửi những dữ liệu đơn giản – Máy chủ... Connection.setRequestProperty(« ContentLength », String.valueOf(byteStream.size())) ; Connection.setRequestProperty(« ContentType », «application/x-www-formurlencoded ») ; byteStream.writeTo(connection.getOutputStrea m()) ; Sending Post Data to Server • Gửi dữ liệu đến Servlet sẽ được trả về một trang web HTML sẽ hiển thị form dữ liệu mà nó đã nhận được Sending Post Data to Server Bypassing the HTTP server • Nếu bạn đang sử dụng applet... PrintWriter(byteStream, true); Out.Print(data) ; Out.flush() ; Connection.setRequestProperty(« Cont ent-Length », String.valueOf(byteStream.size())) ; Connection.setRequestProperty(« Cont ent-Type », «application/x-www-formurlencoded ») ; Sending Post Data to Server • Kiểu ký tự và nhị phân (tt) byteStream.writeTo(connection.getOutputStr eam()) ; • Đăng dữ liệu ByteArrayOutputStream byteStream = new ByteArrayOutputStream(512)... ONFOCUS, ONBLUR, ONKEYDOWN, ONKEYPRESS, ONKEYUP Text Areas • HTML Element: • • Attributes: • NAME (required), ROWS (required), COLS (required), WRAP (nonstandard), DISABLED, READONLY, ONCHANGE, ONSELECT, ONFOCUS, ONBLUR, ONKEYDOWN, ONKEYPRESS, ONKEYUP Submit Buttons • HTML Element: • (No End Tag) • Attributes: • NAME, VALUE, DISABLED, . #$%%#&'( #) • *+ , # +# /0/,,#1/#2 ##// +  #+ -#3##/%%# + / +# # + • 4#(54///%, #++ #  #+  + 3#/%%#&'(#) •. #&//)E 4#( ,+ //, 4## • fq&) 5"H + &)E ,#," ;+# :# #+ (,%#!&jk,#2 ;#km[4"/#5H&-!#4#/9" ;+ 0#&)))E ,#," ;+# :# #+ (,%#!&jk,#2 !%#km[j/%%/,l123332H,92 #,#km)E -!#4#/9"3#,&,#,"#5%4#/ 9&))E 4#( ,+ //, 4## • g<4##+r<=> 89/3#-'G;+r H,99s<? a<=>  4#( ,+ //, 4## 6!% /++ #'( +# # • -t</+gN/%%#. %bi% *#(/#A#,#6 /+# &)E 4%,,,A #(/#"#(,,,&)E 4 ,+ A#(/#"#' ,+ &)E Q%,A#(/#"#(,&)E 44HH1Ajkl+##l4, 9+# #kmE *:;//*:;A#3*:;&%,,,[ ,+ [ %,[4HH1)E 4#( ,+ //, 4## • h %bi%&) *:;,#,,#,A //*:;",%#,#,&)E ,#," ;+#  *+# / #+& amp;H/ +# )E ,#," ;+# ,5%&#)E • 7ni%d 6!#$/!5%4#/9-!#4#/9A #36!#$/!5%4#/9&oIK)E 4#( ,+ //, 4## • 7ni%d&) (p#,A#3 (p#&-!#4#/9[#)E 5"(&//)E5"H + &)E ,#," ;+# :# #+ (,%#!&jk, #2;#km[ 4"/#5H&-!#4#/9" ;+ 0#&)))E ,#," ;+# :# #+ (,%#!&jk, #2!%#km[j/%%/,l123332H,92 #,#km)E 4#( ,+ //, 4## • 7ni%d&) -!#4#/9"3#,&,#,"#5%4 #/9&))E • fq 6!#$/!5%4#/9-!#4#/9A#3 6!#$/!5%4#/9&oIK)E 5

Ngày đăng: 07/08/2014, 15:21

TỪ KHÓA LIÊN QUAN

w