Presentation is loading. Please wait.

Presentation is loading. Please wait.

JSON.

Similar presentations


Presentation on theme: "JSON."— Presentation transcript:

1 JSON

2 JSON JavaScript Object Notation
a lightweight text-based open standard designed for human- readable data interchange. Derived from JavaScript for representing singleton

3 JSON Example { “someString: “asas”, “someNum” : 4,
“someArr” : [“aa”,”bb”], “someJson”: { someStr2:”aaa”} }

4 JSON and AJAX JSON is the most standard data format for ajaxing

5 JSON and JavaScript String to Object: str.parseJSON();
Object to String JSON.stringify(obj);

6 JSON in Java GSON A free open source that helps translate object<-> JSON

7 Cookies

8 Cookies A piece of text stored by a user's web browser
Key-value format May be encrypted With or without an expiration date. Cookies without an expiration date exist until the browser terminates Cookies can’t be used as a virus

9 Usage HttpSession Personalization Tracking (e.g. “Remember me?”)
3rd parties cookies

10 Implementation

11 Cookies and HTTP Cookies are part of the Http request and Response headers Request: “Set-Cookie: name=value“ Response: “Cookie: name=value”

12 Cookies and JavaEE Adding a cookie: Reading cookies:
 Cookie cookie = new Cookie("CName","Cookie Value");   cookie.setMaxAge(100); //in seconds   response.addCookie(cookie); Reading cookies: Cookie[] cookies = request.getCookies();

13 Cookies and JavaScript
Creating a cookie: document.cookie = name+"="+value+expires+"; Reading all cookies: var cookiesArray = document.cookie.split(';'); Erasing a cookie Same as creating whereas “expires = -1”;

14 Session hijecking

15 HttpFilters

16 Filter is like a lightweight servlet that
doesn't generate its own content instead it plugs into the request handling process and executes in addition to the normal page processing. Filters can be applied to any resource Filter implements the interface javax.servlet.Filter, and configured in the web application web.xml file doFilter()

17 Filter Example doFilter(request, response, FilterChain chain) {
long startTime = System.currentTimeMillis(); chain.doFilter(request, response); long stopTime = System.currentTimeMillis(); System.out.println("Time to execute request: " + (stopTime - startTime) + " milliseconds"); {

18 In Web.xml <filter> <filter-name>Timer</filter-name>
<filter-class>internet.demo.Timer</filter-class> </filter> <filter-mapping> <url-pattern>/*</url-pattern> // any file.. </filter-mapping

19 Other usages Auto-redirect to login page …
Block access to resources such as pictures..

20 Servlet 3.0

21 New Version for servlets
Annotations @Servlet(urlMappings={"/MyApp"}) // no web.xml @GET on any method // no web.xml Asynchronous Support the Servlet Engine “understands” that this thread can be suspended

22 Chrome Extensions

23 Chrome Extension Chrome is a web browser developed by Google
It was first released on September 2008 Chrome is the third most widely used browser, with 13.35% of worldwide usage Chrome includes V8 A JS VM

24 Extension An extension is a zipped bundle of files—HTML, CSS, JavaScript, images.. adds functionality to the Chrome browser. Extensions are essentially web pages.

25 Popup extension Manifast.json { "name": "My First Extension",
"version": "1.0", "description": "The first extension that I made.", "browser_action": "default_icon": "icon.png" "popup": "popup.html" }, "permissions": [ " ] }

26 Background extension Manifast.json { "name": "My First Extension",
"version": "1.0", "description": "The first extension that I made.", "background_page": "bg.html", "permissions": [ " ] }

27 The backgroundPage.html:
<html> <body> <script type="text/javascript"> //the extension functionality here </script> </body> </html>

28 API for background chrome.browserAction.onClicked.addListener(
function(tab){ //do something when someone click} ); chrome.tabs.executeScript(tabs[i].id, {“code”:code} chrome.management.onInstalled.addListener().. API: html

29 Tutorial

30 Q/A


Download ppt "JSON."

Similar presentations


Ads by Google