Unit 8 Flashcards

1
Q

SAQ 1 - A What are the advantages and disadvantages of servlets compared to Applets in providing dynamic content for web pages?

A
  • Applets run on the client machine, and so can be very responsive since 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 power of the Java language and its libraries; they can access other servers and invoke other programs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

Each CGI script starts a separate process in response to an HTTP request and closes the process after responding. Servlets are more efficient in the following ways. - Once started 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

SAQ 2 - A How can Java servlets deal with a number of concurrent HTTP requests?

A

A servlet is automatically multithreaded – it creates a new thread for each HTTP request it receives, so it can deal with a number of concurrent requests.

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

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

A

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

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

A

Data stored in instance variables or static variables of the servlet is shared between any active threads, and so special care (such as synchronisation) must be taken if such 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

SAQ 3 - A How do JSP pages differ from Java HTTP servlets?

A

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

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

A

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. You can also create your own custom actions

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

SAQ 3 - C Explain the role of scriptlets in JSP and how they differ from JSP expressions.

A

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

SAQ 3 - Custom

Explain the proccess of how JSP works.

A

When a JSP page is invoked, it is actually translated to a servlet which runs in a web container in the usual way.

The first time a JSP page is accessed after being loaded, it must be translated to a servlet and then compiled to bytecode. This servlet bytecode is stored to respond to any further access to that particular JSP page. This process is handled automatically by the web container. Hence, the first access to a JSP page normally takes longer than any subsequent accesses.

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

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

A

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 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 an 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 the 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
11
Q

SAQ 5 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

There are two main arguments for this. First, it helps to separate 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 source files containing complex interleaving of tags and Java code. Second, 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
12
Q

SAQ 6 - A What are the three main components of the MVC approach?

A

They are the model, the view and the controller. The model represents business 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
13
Q

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

A

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
14
Q

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

A

Servlets are useful for more 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
15
Q

SAQ 7 - B When should you use JSP?

A

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
16
Q

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

A

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 weaknesses, 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.