Anda di halaman 1dari 5

COMP 173 - Final Exam

Time Allowed: 2 Hours

June 25, 2009


page 1 of 5

Name: _________________________

Time allowed = 2 Hours. The number of marks allocated per question appears in parentheses: total = 53.
1.

(1) Concerning server resources, what is the biggest advantage of servlets when compared to CGI?

2.

(2) Why must our code be thread-safe when writing a servlet?

3.

(2) Describe two of the services that a servlet engine provides to support the running of servlets.

4.

(1) Why might we want to use a synchronized method in a servlet?

5.

(2) Describe the purpose of each of these methods:


a) getInitParameter() in the class ServletConfig

b) getParameter() in the class HttpServletRequest

6.

(1) Explain why (or why not) a servlet programmer is responsible for writing the code that creates the
HttpServletRequest and HttpServletResponse objects.

7.

(1) What is the purpose of the <%=

8.

(2) Complete the following page directive so that it imports java.util.* and java.io.*
<%@ page language=java

%> tag in JSP?

COMP 173 - Final Exam


Time Allowed: 2 Hours

9.

June 25, 2009


page 2 of 5

Name: _________________________

(2) When using a bean, we can use the setProperty tag from a JSP. What is the effect of the property="*" in <jsp:setProperty name="myBean" property="*" />

10. (2) We can include Java code in a JSP using either the code fragment tag <% %> or the
declaration tag <%! %>. What is the difference between these two approaches?
(Hint: think of where the code ends up in the generated servlet)

11. (1) One of the JSP page directives is errorPage. What happens when we use this directive?

12. (2) A Java bean must have a no-argument constructor. What other two requirements are there?

13. (2) a) What is an advantage of using cookies as compared to using hidden variables?

b) What is an advantage of using hidden variables as compared to cookies?

14. (1) When developing web applications, it can be difficult to test and debug Java code that is inside of JSP
or JSF pages. What should we do to improve this situation?

15. (2) The lecture notes describe four benefits of using JavaServer Faces. Describe two of them.

16. (1) What does the following statement do?



Class.forName("org.postgresql.Driver");

COMP 173 - Final Exam


Time Allowed: 2 Hours

June 25, 2009


page 3 of 5

Name: _________________________

17. (2) With our JSP shopping cart, we used GetLoginData.jsp to retrieve the users login data and save it in the
Customer bean. Explain why we didnt need GetLoginData.jsp when we used JavaServer Faces.

18. (2) JavaServer Faces supports advanced navigation rules in its configuration file. Explain or give an example of this advanced navigation capability.

19. (1) When using a managed bean in JSF, how do we get initial values to be displayed on a form?

20. (3) Explain what:



a) the first boldfaced line of JSP code does

b) the other block of six boldfaced lines of JSP code do
I dont want to know what the output is, I want to know what is happening
<h:form id="helloForm1">
<h2>Hi. My name is Duke. Im thinking of a number from
<h:outputText value="#{UserNumberBean.minimum}"/> to
<h:outputText value="#{UserNumberBean.maximum}"/>.
Can you guess it?</h2>
<h:graphicImage id="waveImg" url="/wave.med.gif" />
<h:inputText id="userNo" label="User Number"
value="#{UserNumberBean.userNumber}">
<f:validateLongRange
minimum="#{UserNumberBean.minimum}"
maximum="#{UserNumberBean.maximum}" />
</h:inputText>
</h:form>

COMP 173 - Final Exam


Time Allowed: 2 Hours

June 25, 2009


page 4 of 5

Name: _________________________

21. (2) With JDBC, if we have multiple statements that we want to group into a single transaction, what steps
should we take?

22. (2) Explain the purpose of the question marks in a PreparedStatement such as
PreparedStatement con.prepareStatement(
"update table1 set SALES = ? WHERE name LIKE ?");

23. (2) When using JDBC, there are two basic types of commands that we can use with a Statement object.
Describe the purpose of both of these.
Statement stmt = db.createStatement()
result1 = stmt.executeQuery(queryString);
result2 = stmt.executeUpdate(updateString);

// The Statement object


// First basic command type
// Second basic command type

24. (1) In Jakarta Struts, the controller is implemented using a __________________.


25. (2) In our struts-config.xml, there are entries such as:
<action-mappings>
<action path="/login"
name="userStuff"
input="/login.jsp"
scope="request"
type="com.myapp.struts.LoginAction"
validate="true">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/login.jsp"/>
</action>
</action-mappings>

a) What is the purpose of the "forward" entries?

b) Where are the outcomes (success or failure) generated (be specific)?

COMP 173 - Final Exam


Time Allowed: 2 Hours

June 25, 2009


page 5 of 5

Name: _________________________

26. (2) Briefly describe the Model-View-Controller design pattern that is used in Jakarta Struts.

27. (2) TCP sends data in numbered segments whereas UDP uses datagrams.
What are two advantages of TCP?

28. (1) Give an example of an application where it is better to use UDP rather than TCP.
29. (4) For our ChatServer, we used a thread for the GUI, a thread for the server loop, and a thread for each client. Explain why this was required.

30. (1) The constructor that we used for MulticastSocket is MulticastSocket(int port);
What is the purpose of the subsequent call to joinGroup(InetAddress addr)?

31. (2) In the lab, we used a ServerSocket..


a) Describe the pupose of the accept() method.

b) What does the accept() method return?

Anda mungkin juga menyukai