[Web Sistemak] 11. ESKOLA (2017/03/07): Web Orrialde Dinamikoak: JSP eta JavaScript

Please download to get full document.

View again

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
 23
 
  1. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática 1 Web Sistemak by Oskar Casquero & María Luz Álvarez is licensed under a…
Related documents
Share
Transcript
  • 1. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática 1 Web Sistemak by Oskar Casquero & María Luz Álvarez is licensed under a Creative Commons Reconocimiento 4.0 Internacional License. WEB ORRIALDE DINAMIKOAK: JSP ETA JAVASCRIPT Web Sistemak 11. ESKOLA (2016/03/07)
  • 2. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática • Printzipioz, HTML orrialdeak dokumentu estatikoak dira, hau da, – web orrialde baten eduki jakin batentzako HTML dokumentu jakin bat dago. – web orrialdearen edukia aldatu nahi bada, HTML dokumentua aldatu beharra dago. • Demagun web orrialde batean ordua inprimatu nahi dela. Printzipioz, denbora bereiztasuna bezain beste HTML behar dira. JAVA SERVER PAGE 2 <html> ... <footer> Server Date: Fri Mar 04 08:43:33 CET 2016 </footer> … </html> HTML t1 <html> ... <footer> Server Date: Fri Mar 04 08:43:34 CET 2016 </footer> … </html> HTML t2 <html> ... <footer> Server Date: Fri Mar 04 08:43:59 CET 2016 </footer> … </html> HTML tN
  • 3. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática JAVA SERVER PAGE 3 Java + HTML <%@ page language="java" …%> <%@ page import="java.util.*"%> <html> ... <body> Server Date: <%= new Date().toString() %> </body> … </html> <html> ... <body> Server Date: Fri Mar 04 08:43:33 CET 2016 </body> </html> HTML instantzia JSP ZERBITZARIAFitxategi bakarra Java exekutatu Bezeroari (nabigatzaileari) bidaltzen zaiona
  • 4. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática • Demagun web orrialde batean datu base baten edukiak inprimatu nahi direla t=2, t=4 eta t=6 aldiuneetan. – t=1 aldiunean datu baseak erregistro bat dauka. – t=3 aldiunean datu basean beste erregistro bat gordetzen da. – t=5 aldiunean datu basean beste erregistro bat gordetzen da. • Printzipioz, aldiune bakoitzean datu baseak dituen datu erregistro bezain beste lerro dituzten HTML taulak behar dira. JAVA SERVER PAGE (BESTE ADIBIDE BAT) 4 <html> ... <table> <tr><td>Oskar</td></tr> </table> … </html> HTML t=2 <html> ... <table> <tr><td>Oskar</td></tr> <tr><td>Mariluz</td></tr> </table> … </html> HTML t=4 <html> ... <table> <tr><td>Oskar</td></tr> <tr><td>Mariluz</td></tr> <tr><td>Ariana</td></tr> </table> … </html> HTML t=6
  • 5. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática JAVA SERVER PAGE (BESTE ADIBIDE BAT) 5 Java + HTML <%@ page language="java" …%> <%@ page import="java.util.*"%> <% ArrayList<Str> userList = (ArrayList) request.getAttribute(“userList"); %> <html> ... <table> <% for(int i = 0; i < userList.size(); i++) { Str username = userList.get(i); %> <tr><td><%= username %></td></tr> <% } %> </table> … </html> <html> ... <table> <tr><td>Oskar</td></tr> <tr><td>Mariluz</td></tr> <tr><td>Ariana</td></tr> </table> … </html> HTML instantzia JSP ZERBITZARIAFitxategi bakarra Java exekutatu Bezeroari (nabigatzaileari) bidaltzen zaiona [“Oskar”, “MariLuz”, “Ariana”]
  • 6. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática JAVA SERVER PAGE (BESTE ADIBIDE BAT) 6 Java + HTML <%@ page language="java" …%> <%@ page import="java.util.*"%> <% ArrayList<Str> userList = (ArrayList) request.getAttribute(“userList"); %> <html> ... <table> <% for(int i = 0; i < userList.size(); i++) { Str username = userList.get(i); %> <tr><td><%= username %></td></tr> <% } %> </table> … </html> <html> ... <table> <tr><td>Oskar</td></tr> <tr><td>Mariluz</td></tr> <tr><td>Ariana</td></tr> </table> … </html> HTML instantzia JSP ZERBITZARIAFitxategi bakarra Java exekutatu Bezeroari (nabigatzaileari) bidaltzen zaiona for() -aren barnean gelditzen den HTML kodea for() -a exekutatzen den bezain beste aldiz inprimitzen da userList = [“Oskar”, “MariLuz”, “Ariana”]
  • 7. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática JARDUERA: CACHE-AREN ARIKETAREN IRTEERA JSP BATERA ERAMAN 7 PrintWriter http_out = response.getWriter(); http_out.println("HTTP eskaeraren goiburuak:"); Enumeration<String> headerNames = request.getHeaderNames(); http_out.println("<table border="1">"); http_out.println("<tr>"); http_out.println("<th>GOIBURUAREN IZENA</th>"); http_out.println("<th>GOIBURUAREN BALIOA</th>"); http_out.println("</tr>"); while(headerNames.hasMoreElements()) { http_out.println("<tr>"); String headerName = (String)headerNames.nextElement(); http_out.println("<td>"); http_out.println(headerName); http_out.println("</td>"); http_out.println("<td>"); http_out.println(request.getHeader(headerName)); http_out.println("</td>"); http_out.println("</tr>"); } http_out.println("</table>"); Kode honetan bista (HTML) eta kontrola (Java) banandu nahi ditugu
  • 8. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática JAVA SERVER PAGE VS JAVASCRIPT 8 <%@ page import="java.util.*"%> ... <body> Server Date: <%= new Date().toString() %> <script language="javascript"> var data = new Date(); document.write("Client Date: "); document.write(data); </script> </body> JSP: zerbitzariak exekutatzen du ... <body> Server Date: Fri Mar 04 08:43:33 CET 2016 <script language="javascript"> var data = new Date(); document.write("Client Date: "); document.write(data); </script> </body> Bezeroari heltzen zaiona Zerbitzaria
  • 9. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática ... <body> Server Date: Fri Mar 04 08:43:33 CET 2016 <script language="javascript"> var data = new Date(); document.write("Client Date: "); document.write(data); </script> </body> JAVA SERVER PAGE VS JAVASCRIPT 9 JavaScript: bezeroak exekutatzen du Server Date: Fri Mar 04 08:43:33 CET 2016 Client Date: Fri Mar 04 08:43:33 GMT+0100 Bezeroari heltzen zaiona Bezeroan bistaratzen dena
  • 10. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática 10 JAVASCRIPT • OHARRA: JS-ak HTML dokumentuaren DOM-a aldatu dezake. Beraz, deskargatzen dugun web orriak eta nabigatzailean bistaratzen denak ez dute kode berdina. • Ariketa: – Firefox-en “View Source Chart” osagarria instalatu – Web orrian eskumako botoia sakatu eta • “View Page Source” aukeratu • “View Source Chart” aukeratu emaitzak alderatu
  • 11. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática 11 JAVASCRIPT “View Page Source” “View Source Chart”
  • 12. Oskar Casquero y María Luz Álvarez Dpto. Ingeniería de Sistemas y Automática 12 JAVASCRIPT • Web Scraping egiterakoan zelan irakurri dezagu JS exekutatu ostean lortzen den HTML kodea? Nabigatzailetik pasatuz! webdriver bat erabiliz, adibidez: Selenium (http://selenium-python.readthedocs.io/) import httplib from bs4 import BeautifulSoup conn = httplib.HTTPConnection('localhost', 8080) conn.connect() conn.request('GET', '/jspVSjs/jsp/weborria.jsp') erantzuna = conn.getresponse() html = erantzuna.read() conn.close() soup = BeautifulSoup(html, 'html.parser') body = soup.find_all('body') print body from selenium import webdriver from bs4 import BeautifulSoup browser = webdriver.Firefox(executable_path='C:geckodriver.exe') browser.get('http://localhost:8080/jspVSjs/jsp/weborria.jsp') html = browser.page_source browser.quit() soup = BeautifulSoup(html, 'html.parser') body = soup.find_all('body') print body [<body>rn Server Date: Tue Mar 07 12:13:59 CET 2017rn <br/>n<script src="/jspVSjs/js/data.js"></script>n</body>] [<body>n Server Date: Tue Mar 07 12:13:59 CET 2017n <br>n<script src="/jspVSjs/js/data.js"></script>Client Date: Tue Mar 07 2017 12:13:59 GMT+0100 (Romance Standard Time)ntn</br></body>] HTTP erantzunaren edukiaren azterketa Edukiaren azterketa nabigatzailetik pasa ostean
  • Related Search
    We Need Your Support
    Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

    Thanks to everyone for your continued support.

    No, Thanks
    SAVE OUR EARTH

    We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

    More details...

    Sign Now!

    We are very appreciated for your Prompt Action!

    x