Unit 8 The web tier Flashcards

1
Q

What are the advantages and disadvantages of servlets in comparison to applets in providing dynamic content for web pages?

A

(Part 2) The advantages and disadvantages are:

  • Applets run on the client machine, and so can be very responsive because there are no network delays
  • The applet code must be downloaded from a server before running, making it less attractive to write large applets
  • Servlets are more scalable - additional servers can be used to run more servlets if there is heavy demand on the system, or to provide backup in case of server failure
  • Untrusted applets have severe security restrictions that limit what they are permitted to do on the client machine - although most of these can be avoided using trusted applets
  • Since servlets are stored and run in a controlled environment on the server, they do not need to have such security restrictions: they can use the full Java language and its libraries, access other servers and invoke other programs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the advantages and disadvantages of servlets compared to CGI scripts in providing dynamic content for web pages?

A

(Part 2) Each CGI script starts a seperate process in response to an HTTP request and closes the process after responding.

Servlets are more efficient in these ways:

  • Once starte up they continue running on the server and can deal with a succession of HTTP requests, possibly from multiple clients
  • they use threads rather than processes to service any concurrent requests
  • They make it easy to store the state of a session and to maintain links to resources like a database
    *
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can Java servlets deal with a number of concurrent HTTP requests?

A

(Part 2) A servlet is automatically multithreaded - it creates a new thread for each HTTP request it receives, so it can deal with a number of multithreaded requests.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which method is run by a servlet in response to each user request, and what is the purpose of this method?

A

(Part 2) Each thread runs the service method which in turn invokes a helper method such as doGet or doPost, corresponding to the type of request being processed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What issues arise in respect of shared resources, and how can they be dealt with?

A

(Part 2) Data stored in instance variables or static variables of the servlet is shraed between any active threads, so special care (for example synchronisation) must be taken if this data is updated, to avoid data corruption. The same precautions apply to any resources such as network links or database connections shared between threads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Howdo JSP pages differ from Java HTTP servlets?

A

(Part 3) Both can produce a response to an HTTP request. A JSP page can contain a mixture of static elements (text, HTML or XML) and dynamic elements (fragments of Java code).

A Java HTTP servlet is entirely written in Java and is an instance of a class that inherits from the HTTPServlet class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the main categories of tag used in JSP, and what is each category used for?

A

(Part 3) The categories are directive tags, scripting tags and action tags:

  • Directive tags (such as the page directive) provide information to the JSP container about the page, and affect how the JSP compiler generates the servlet
  • Scripting tags allow the inclusion of fragments of Java in a JSP page. There are three types of scripting tag - declaration, scriptlet and expression
  • Action tags specify some sort of action to be carried out by the JSP page. They may be standard actions such as including applet code in the JSP page or forwarding control to another JSP page. Custom actions can also be created.
    *
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the role of scriptlets in JSP and how do they differ from JSP expressions?

A

(Part 3) A scriptlet is a fragment of Java code, consisting of one or more complete Java statements that will be executed when the JSP page runs.

A JSP expression contains a Java expression that produces a value, and this value will be displayed as part of the output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between a JavaBean and an EJB (Enterprise JavaBeans) component?

A

(Part 4) JavaBeans are defined as special Java classes and can be used on any tier in a Java EE system or in ordinary Java applications. A JavaBean class must have a zero-argument constructor. Every readable property of the bean must have a getter method and every writeable property must have a setter method. In Java EE web tier programming they are very useful for temporary storage of data and also for data transfer among servlets and JSP pages.

Enterprise JavaBeans are server-based components for Java EE systems, running within and EJB container and used for the business tier of an application. EJB session beans are used to define the business logic of a Java EE application. They have a business interface that defines their publicly available methods, and this can be configured for either local access (within same JVM) or remote access (from another JVM, possibly on a remote computer).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the main reasons suggested for using JSTL tags and JSP expression language in JSP pages in preference to Java scriptlets and expressions?

A

(Part 5) There are two main arguments in favour of JSTL tags and JSP expression language:

  • It helps to seperate processing (Java code in servlets) from presentation (JSP pages using tags and EL). This may help maintenance in complex applications - for example, presentation aspects could be changed without any accidental changes to processing if the two are adequately separated. It can also be hard to read souce files containing complex interleaving of tags and Java code.
  • It allows web designers familiar with HTML and XML, but not with Java, to produce and maintain JSP pages without any Java programming.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the three main components of the MVC approach?

A

(Part 6) The model, view and controller.

  • The model represents data and associated business logic
  • The view makes the contents of the model visible
  • The controller regulates the overall behaviour of the application
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can the MVC approach be applied in web-based information systems using Java EE?

A

(Part 6) In a Java EE application the model typically uses EJBs and JavaBeans. In web applications the view component normally refers to constructing one or more dynamic web pages using JSP.

The controller may receive user inputs directly or forwarded via view components. In a web application the user inputs are mainly HTTP GET or POST requests - typically the controller will consist of one or more servlets. As a result of these requests, it may interact with the model, potentially invoking actions by the model such as updating some data. It also decides which view components are displayed in response to requests and any resulting internal operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the primary role of servlets in a web-based information system?

A

(Part 6) Servlets are useful for complex processing, where the static content of the response is very limited or is delegated to another component.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When should JSP be used?

A

(Part 6) JSP is particularly suited to constructing dynamic web pages in situations where the output is predominantly static HTML or XML.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can servlets and JSP be combined in complex web-based systems?

A

(Part 6) Both technologies are used by a server to create a web page in response to a client request. Servlets and JSP are complementary in their strengths and weaknesse, and most systems of significant complexity would require a combination of both.

Servlets can invoke JSP pages and vice versa so that both can carry out the aspects of the response to which they are best suited. The MVC pattern is usually recommended as a guideline for the roles of servlets and JSP in web applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly