Unit 8 - The Web Tier - Servlets, GET & POST, JSPs, JavaBeans, MVC architecture Flashcards

1
Q

What is the main function of the web tier?

A

The code associated with the web tier runs on the server machine. It sits between the business and client tier.
Received requests from clients and responds by dynamically contsructing web pages using servlets and JSP. Communication is made using HTTP.

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 applets in providing dynamic content for web pages?

A
  • Applets run on the client machine and can be very responsive as there are no network delays.
  • Applet code must be downloaded from the server before running, this makes it less attractive to write large applets.
  • Servlets are more scalable - more servers can be added to provide back up or to cope with heavy demand.
  • Untrusted applets have severe security restrictions which limits what they can do on the client machine, though trusted applets can get around this.
  • Because servlets are run and stored in the controlled server environment they don’t need such severe security restrictions. Also they have access to the full power of Java and its libraries. They can access other servers and invoke programs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the advantages and disadvantages of servlets compared to CGI scripts?

A

Each CGI script starts a separate process in response to an HTTP request which it closes after responding.
Servers are more efficient: -
- once started they run on the server and can deal with a succession of HTTP requests possibly from many clients
- they use threads rather than processes to service concurrent requests
- they make it easy to store the state of a session and maintain links to resources like a database.

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

How are servlets run?

A

They run in a web container that handles security, concurrency and the servlet lifecycle. The preferred approach is to use a multithreaded servlet (handles concurrent requests using a thread for each request) with control over access to shared resources.

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

How is a servlet programmed?

A

import javax.servlet.*;
this gives you access to the Servlet interface
HTTPServlet implements init(initialises) service(handles requests), destroy(clean up before closing servlet)
so,
public class exampleServlet extends HttpServlet
then override the service methods, most commonly
doGet and doPost

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

When a servlet receives an HTTP request it invokes the service method and passes it references to two objects of classes HttpServletRequest and HttpServletResponse. What do these classes do?

A

HttpServletRequest - contains details of the request, including the method name (eg GET) and any paramaters or data
HttpServletResponse - constructs the response to be returned to the client.

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

What further expectations does the Java EE API place on the behaviour of HTTP servlet methods that respond to GET and POST requests?

A

Get should be safe i.e. not change any stored data in databases. Get should be idempotent - safely repeated, it should leave the system in the same state.
doPost - does not have to be idempotent, ops reqeusted through post can have side effects for which the user can be held accountable e.g. updating stored data, or buying something.

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

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

A

A server 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
9
Q

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 helper methods such as doGet or doPost, depending on the type of request being processed.

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

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

A

Data stored in instance variables or static variables should be synchronised if such data is updated. 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