CS 412 Web Development

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is the default of a servlet?

Default servlets is a text not a html

What are Servlets?

Servlets are Java programming language classes that dynamically process requests and construct responses

php does have one important facility that is generally unlike other web programming languages, what is it?

The ability to include or insert content from one file into another

How to generate a POST Request?

The only way to generate a POST request is through a form that uses a POST request

in php, what is Sanitizing user inputs?

The process of checking user input for incorrect or missing information => distrust all user input

Pass Parameters by Value in php?

by default, arguments passed to functions are passed by value in PHP. This means that PHP passes a copy of the variable so if the parameter is modified within the function, it does not change the original.

How to set the maximum age of a persistent cookie?

cookieName.setMaxAge (the argument is in seconds);

How do you refer to the length of an array in php?

count($nameOfArray);

What are the ways to generate a GET request?

➢ A form w/ get method ➢ A link from another page ➢ From a url (is always a get request)

What are the two type of functions in php?

➢ A user-defined function is one that you the programmer define. ➢ A built-in function is one of the functions that come with the PHP environment

What are the Java EE client types?

➢ A web client ➢ An application client

Disadvantage of URL rewriting?

➢ All URLs that refer to your own site must be encoded ➢ All pages must be dynamically generated ➢ It fails for bookmarks and links from other sites

The HTTP response status line consists of?

➢ An HTTP version ➢ A status code ➢ An associated message

How cookies work for session tracking?

➢ Associating a cookie with data on the server ➢ Extracting the cookie that stores the session identifier ➢ Setting the appropriate expiration inactive interval time for the session ➢ Associating the hash tables with each request ➢ Generating the unique session identifiers

How can information be added to a session? in two ways?

➢ By adding a new session attribute ➢ By augmenting an object that is already in the session

Java EE multitiered applications are generally considered to be three-tiered applications because they are distributed over three locations. What are those locations?

➢ Client machines ➢ The Java EE server machine ➢ The database or legacy machines at the back end

Redirects are useful for?

➢ Computing destinations ➢ Tracking user behavior ➢ Performing side effects

What are the three Typical Solutions for session tracking?

➢ Cookies ➢ URL rewriting ➢ Hidden form fields

Advantages of Session Tracking in Servlets

➢ Doesn't need to bother with many of the implementation details ➢ Doesn't have to explicitly manipulate cookies or information appended to the URL ➢ Is automatically given a convenient place to store arbitrary objects that are associated with each session

What are the three main mechanisms for maintaining uploaded file size restrictions?

➢ HTML in the input form ➢ via JavaScript in the input form ➢ via PHP coding

in php, what do the $_SERVER associative array contains?

➢ HTTP request headers (send by client) ➢ Configuration options for PHP

Disadvantages of Hidden form fields?

➢ It requires lots of tedious processing ➢ All pages must be the result of form submissions

LAMP software Stack

➢ Linux operating system ➢ Apache web server ➢ MySQL DBMS ➢ PHP scripting language

What are a Servlet's Jobs?

➢ Read explicit data sent by client (form data) ➢ Read implicit data sent by client (request headers) ➢ Generate the results ➢ Send the explicit data back to client (HTML) ➢ Send the implicit data to client (status codes and response headers)

Why Build Web Pages Dynamically?

➢ The Web page is based on data submitted by the user. E.g., results page from search engines and order-confirmation pages at on-line stores ➢ The Web page is derived from data that changes frequently. E.g., a weather report or news headlines page ➢ The Web page uses information from databases or other server-side sources. E.g., an e-commerce site could use a servlet to build a Web page that lists the current price and availability of each item that is for sale.

How URL rewriting works for session tracking?

➢ The client appends some extra data on the end of each URL that identifies the session ➢ The server associates that identifier with data it has stored about that session

Why session tracking?

➢ When clients at an on-line store add an item to their shopping cart, how does the server know what's already in the cart? ➢ When clients decide to proceed to checkout, how can the server determine which previously created cart is theirs?

in order for php to upload files, HTML Requires?

➢ You must ensure that the HTML form uses the HTTP POST method ➢ You must add the enctype="multipart/form-data" attribute to the HTML form that is performing the upload ➢ You must include an input type of file in your form

php provides four different statements for including files, what are they?

➢ include "somefile.php"; ➢ include_once "somefile.php"; ➢ require "somefile.php"; ➢ require_once "somefile.php";

Apache runs in two possible modes...

➢ multi-process (also called preforked) ➢ multi-threaded (also called worker)

A web client is sometimes called ???

A thin client

What are functions' parameters?

Parameters are the mechanism by which values are passed into functions.

How to look up information associated with a session?

session.getAttribute("key") method on the HttpSession object

How to Associates a value with a name? session tracking

setAttribute(String name, Object value);

in php, how to sort an array by its values?

sort($nameOfArray);

in php, what are the most important superglobal arrays?

$_GET and $_POST because they allow the programmer to access data sent by the client in a query string.

How to declare an array in php?

$nameOfArray = array();

php Data types?

(FAS-BOI) ➢ Float ➢ Array ➢ String ➢ Boolean ➢ Object ➢ Integer

What is a Constructor in php? and how to define it?

In PHP, constructors are defined as functions (as you shall see, all methods use the function keyword) with the name __construct(). e.g- function__construct(parameters list)

What is Apache web server?

It is the intermediary that interprets HTTP requests that arrive through a network port and decides how to handle the request, which often requires working in conjunction with PHP

Advantage of Hidden form fields?

It works even if cookies are disabled or unsupported

What are Java Server Pages (JSP) ?

JSP pages are text-based documents that execute as servlets but allow more natural approach to create static content.

How to extract a previously stored value from a session object? it returns null if no value is associated with the given name.

getAttribute(String name);

How to return names of all attributes in the session? session tracking

getAttributeNames( );

These methods provide for specifying the domain to which the cookie applies. The current host must be part of the domain specified.

getDomain/setDomain

How to return the unique identifier generated for each session?

getId( );

These methods get/set the cookie expiration time (in seconds). If this is not set, the cookie applies to the current browsing session only.

getMaxAge/setMaxAge

How to find a cookie? you will need to loop down the array on each entry until the cookie of interest is found

getName() method;

These methods get/set the path to which the cookie applies.

getPath/setPath

These methods get/set values associated with the cookie

getValue/setValue

What is a hash table?

is a built-in data structure in which any number of keys and their associated values of session objects can be stored.

in php, how to check if a value exist for a key?

isset() function;

How to move the temporary file to a permanent location on your server?

move_uploaded_file() takes in the temporary file location and the file's final destination

in php, what are superglobal variables?

predefined associative php arrays that allow the programmer to easily access HTTP headers, query string parameters, and other commonly needed information. They are called superglobal because they are always in scope, and always defined.

Removes values associated with the name? session tracking

removeAttribute(String name);

How to obtain the cookies sent by the browser?

request.getCookies; => this yields an array of cookie objects

How to place the Cookie into the HTTP response or send it back to the browser?

response.addCookie(nameOfCookie);

How to sets a status code (usually 404) ?

sendError method

Advantage of URL rewriting?

This method works even if cookies are disabled or unsupported

What is an Applet?

An applet is a small client application written in the Java programming language that executes in the Java virtual machine installed in the web browser

foreach syntax for normal and for an associative array in php

//normal array foreach($days as $value){ echo $value. "<br />"; } //Associative array foreach($days as $key => $value){ echo $key. " = " .$value. "<br />"; }

What is Function scope in php?

All variables defined within a function have function scope, meaning that they are only accessible within the function. Any variables created outside the function in the main script are unavailable within a function.

Constants in php?

CONSTANTS: They are added to a class using the const keyword. Constants don't use the $ symbol when declaring or using them. e.g- const EARLIEST_DATE = 'January 1, 1200'; o Accessed both inside and outside the class using ➢ self::EARLIEST_DATE in the class and ('self' is equivalent to 'this' in Java) ➢ classReference::EARLIEST_DATE outside

Cookies settings?

Call the Cookie constructor, set the age, then call the response.addCookie mehtod

How to discard an entire session?

Call the invalidate method

How to discard the session data?

Call the removeAttribute method to discard a specific value

Reading cookies?

Call the request.getCookies method, check for the null value, look through the array for a matching name, then, if found, use the associated value

How to access the session object associated with the current request?

Call the request.getSession method to get a HttpSession object

How to create a cookie object?

Cookie c = new Cookie("userID", "a1234");

What are cookies?

Cookies are small bits of textual information that a Web server sends to a browser and that the browser later returns unchanged when visiting the same Web site or domain

The most important fact about php is that...

The programming code can be embedded directly within an HTML file

What is the visibility in php? and its types?

The visibility (or access modifiers) of a property or method determines the accessibility of a class member and can be set to: ➢ Public the property or method is accessible to any code that has a reference to the object ➢ Private sets a method or variable to only be accessible from within the class ➢ Protected is related to inheritance... since there is no inheritance in php, protected means that only accessible to the subclass

In php, how to refer to a single element in the array?

Using Array keys

Pass Parameters by Reference in php?

allow a function to change the contents of a passed variable. The mechanism in PHP to specify that a parameter is passed by reference is to add an ampersand (&) symbol next to the parameter name in the function declaration.

in php, how to collapse or numerically reindex an array?

array_values();

in php, how to sort an array but keep its keys and values associated together?

asort($nameOfArray);

How to output something in php that will be seen by the browser?

echo() function

How to set the arbitrary status codes and set it before sending any document content to the client?

response.setStatus(int statusCode)

How to generate a status code response of 302 and a Location response header giving the URL of a new document?

sendRedirect method

How to delete an array element in php?

unset() function;

How to delete a cookie?

use setMaxAge to assign a maximum age of 0

How to Specify or Store information in a session?

use the setAttribute method with a key and a value.

How php does allow variables with global scope to be accessed within a function?

using the global keyword

Whats is Global scope in php?

variables defined in the main script are said to have global scope. Unlike other programming languages (JavaScript & JAVA), a global variable is not, by default, available within functions.

Include Vs. Require in php

with include, a warning is displayed and then execution continues. With require, an error is displayed and execution stops.

An array is a data structure that ...

➢ Collects a number of related elements together in a single variable. ➢ Allows the set to be Iterated ➢ Allows access of any element

What are the two parts of a web client?

➢ Dynamic web pages containing various types of markup language (HTML, XML, and so on), which are generated by web components running in the web tier ➢ A web browser, which renders the pages received from the server

To define a function with parameters, you must decide?

➢ How many parameters you want to pass in ➢ What order they will be passed ➢ Each parameter must be named

Typical Uses of Cookies?

➢ Identifying a user during an e-commerce session ➢ Remembering usernames and passwords ➢ Customizing sites ➢ Focusing advertising

in php, what are the Request Header Keys?

➢ REQUEST_METHOD returns the request method that was used to access the page: that is, GET, HEAD, POST, PUT ➢ REMOTE_ADDR key returns the IP address of the requestor ➢ HTTP_USER_AGENT contains the operating system and browser that the client is using ➢ HTTP_REFERER contains the address of the page that referred us to this one (if any) through a link

When done with the user's session data, there are three options to discard the session?

➢ Remove only the data your servlet created -> removeAttribute("key") ➢ Delete the whole session -> The invalidate method ➢ Log the user out and delete all the sessions belonging to that user -> logout method

in php, what are the SERVER INFORMATION KEYS?

➢ SERVER_NAME contains the name of the site that was requested ➢ SERVER_ADDR tells us the IP of the server ➢ DOCUMENT_ROOT tells us the location from which you are currently running your script ➢ SCRIPT_NAME key that identifies the actual script being executed

The types of comment styles in php are:

➢ Single-line comments. Lines that begin with a # are comment lines and will not be executed. ➢ Multiline (block) comments. These comments begin with a /* and encompass everything that is encountered until a closing */ tag is found. ➢ End-of-line comments. Whenever // is encountered in code, everything up to the end of the line is considered a comment.

What are the two basic techniques for read/writing files in PHP?

➢ Stream access: In this technique, our code will read just a small portion of the file at a time. While this does require more careful programming, it is the most memory-efficient approach when reading very large files. ➢ All-In-Memory access: In this technique, we can read the entire file into memory. While not appropriate for large files, it does make processing of the file extremely easy.

in php, $_FILES array contains?

➢ The $_FILES array will contain a key=value pair for each file uploaded in the post. ➢ The key for each element will be the name attribute from the HTML form, while the value will be an array containing information about the file as well as the file itself. ➢ The keys in that array are the name, type (defines the MIME type of the file), tmp_name(the full path to the location on your server where the file is being temporarily stored), error(The value for a successful upload is UPLOAD_ERR_OK), and size.

Idea of Cookies?

➢ The servlet sends a simple name and value to the client. ➢ The client returns the same name and value when it connects to the same site.

Cookies let you?

➢ Track sessions (use higher-level API) ➢ Permit users to avoid logging in at low-security sites ➢ Customize sites for different users ➢ Focus content or advertising

A php Constant

➢ Typically defined near the top of a PHP file via the define() function ➢ Once it is defined, it can be referenced without using the $ symbol

Scope of Include files in php

➢ Variables defined within an include file will have the scope of the line on which the include occurs ➢ Any variables available at that line in the calling file will be available within the called file ➢ If the include occurs inside a function, then all of the code contained in the called file will behave as though it had been defined inside that function

What are the shortcut methods provided in HttpServletResponse?

➢ sendRedirect(String url) method generates a status code response of 302 and a Location response header giving the URL of a new document. ➢ sendError(int Code, String message)


Set pelajaran terkait

Science Final Exam Atmosphere Directed Readings

View Set

Mental Health Exam 2 Chapter 18,19,20,21,22 EAQs

View Set

RELATIONS AND FUNCTIONS: FUNCTION NOTATION

View Set

Oral Health and Personal Hygiene

View Set

ATI: Central Venous Access Devices

View Set

3.6/3.7 Parallel and Perpendicular lines in a coordinate plane

View Set