Computer Associates Placement: Sample Questions 12 - 14 of 18

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 12

Appeared in Year: 2004

Question

MCQ▾

In JSP, how can you know what HTTP method (GET or POST) is used by client request?

Choices

Choice (4)

a.

By using request. SetMethod ()

b.

Impossible to know

c.

By using request. GetMethod ()

d.

Question does not provide sufficient data or is vague

Answer

c.

Explanation

  • Each time a client requests a page, the JSP engine creates a new object to represent that request.
  • The request object provides methods to get HTTP header information including form data, cookies, HTTP methods, etc

Question 13

Appeared in Year: 2004

Question

MCQ▾

Why DB connections are not written directly in JSPs?

Choices

Choice (4)

a.

Not a standard J2EE architecture

b.

Response is slow

c.

Load Balancing is not possible

d.

Both a. and c. are correct

Answer

d.

Explanation

  • The main purpose of JSP is to separate the business logic & presentation logic.
  • DB connections deal with pure java code.
  • If write this kind of code in JSP, servlet container converts the JSP to servlet using JSP compiler which is the time consuming process.
  • So, this process is not a standard J2EE architecture and load balancing is not possible.

Question 14

Appeared in Year: 2004

Question

MCQ▾

Which method is called first each time a Servlet is invoked?

Choices

Choice (4)

a.

init ()

b.

Servive ()

c.

Start ()

d.

Run ()

Answer

a.

Explanation

  • When a user invokes a servlet, a single instance of each servlet gets created, with each user request resulting in a new thread that is handed off to doGet or doPost as appropriate.
  • The init () method simply creates or loads some data that will be used throughout the life of the servlet.
  • The init method is called only once. It is called only when the servlet is created, and not called for any user requests afterwards.
  • So, it is used for one-time initializations, just as with the init method of applets.
  • The init method definition looks like this
  1. Publicvoidinit() throwsServletException
  2. {
  3.     // Initialization code..
  4. }

Developed by: