Section 1

Preview this deck

d

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (101)

Section 1

(50 cards)

d

Front

Marks: 0.00/1.00 What is output to the web page on the second access to the same instance of the following JSP? <html> <body> <%! int x = 0; %> <%= x++ %> </body> </html> Choose one answer. a. 0 b. 2 c. 3 d. 1

Back

b

Front

Assuming the user types the correct username and password, then press Login button, what will the servlet output in the response? Choose one answer. a. None of the others. b. The code is invalid and causes the compiling errors c. Welcome to Servlet d. Invalid Username or Password

Back

c

Front

a. None of the others. b. The return type of each create method must be type of the local component interface c. The return type of each create method must be type of the remote component interface d. The CarHome must be extends javax.ejb.EJBLocalHome

Back

a

Front

Consider the following code fragment public class RegistrationBean implements EntityBean { private EntityContext context; private String key; public void setEntityContext(EntityContext aContext) { context = aContext; } public void ejbActivate() { this.key = (String)context.getPrimaryKey(); } public void ejbPassivate() { this.key = null; } public void ejbRemove() { try { deleteRecord(this.key); } catch(Exception e) { throw new EJBException("Remove Errors " + e.getMessage()); } } public void unsetEntityContext() { context = null; } public void ejbLoad() { try { loadRecord(); }catch(Exception e) { throw new EJBException("Load Errors " + e.getMessage()); } } public void ejbStore() { try { storeRecord(); }catch(Exception e) { throw new EJBException("Store Errors " + e.getMessage()); } } //all business method } Assuming all implemented code is valid for Bean Managed Persistence (BMP). Choose the correct answers Choose one answer. a. The code bean is not complete because the code presents lacking the ejbFindByPrimaryKey b. None of the others. c. The code bean is not complete because the code presents lacking the ejbCreate with no or many parameters d. The code is not completer because the code is not implement BeanManagedPersistence class

Back

d

Front

Marks: 0.00/1.00 A JSP page called test.jsp is passed a parameter name in the URL using http://localhost/Final/test.jsp?name=John. The test.jsp contains the following code. <% String myName=request.getParameter("name");%> <% String test= "Welcome " + myName; %> <%=test%> What is the output? Choose one answer. a. The program gives a syntax error because of the statement <%=test%> b. The program gives a syntax error because of the statement <% String test= "Welcome " + myName; %> c. The program gives a syntax error because of the statement <% String myName=request.getParameter("name");%> d. The page display "Welcome John"

Back

a

Front

For what reason does the following JSP fail to translate and compile? <html> <body> <%! int x; %> <%=x ; %> </body> </html> Choose one answer. a. Error in JSP Expression. b. Local variable x not initialized before use. c. Method declared in scriptlet. d. Data member x not initialized before use.

Back

a

Front

The following class represents a valid primary key class does not need to be declared abstract. The container should be allowed to use the primary class without having to extend it. public class AccountKey { private String id; private int number; public String getId() { return id ; } public int getNumber() { return number; } } Choose one answer. a. The code is not valid because it do not obey the rule of primary key in EJB entity. b. The code is not valid because its ejb-jar is not valid. c. None of the others. d. The code is legal.

Back

c

Front

a. An error occurs. b. Output nothing c. Chicago d. LosAngeles

Back

a

Front

a. The Bean cannot mapping to JNDI because the ejb-name of jboss different to ejb-name of ejb-name b. The deployment descriptor ejb-jar is invalid because tag transaction-type must contain Bean value c. None of the others. d. The deployment descriptor is valid

Back

c

Front

a. StudentBean b. Student c. StudentJNDI d. StudentLocalJNDI

Back

a

Front

Assuming the user changes none of the default settings and press Present button, what will the servlet output in the response? Choose one answer. a. This is the value of first control!!! b. This is the value of third control!!! c. This is the value of second control!!! d. None of the others.

Back

a

Front

Marks: 0.00/1.00 What is output to the web page on the second access to the same instance of the following JSP? <html> <body> <%! int x = 0; %> <%! public void jspInit() { System.out.println(x++); } %> <%= x++ %> <% System.out.println(x); %> <% jspInit(); %> </body> </html> Choose one answer. a. 3 b. 2 c. 1 d. 4 e. 0 f. The page can not be translated.

Back

a

Front

a. The Result is : 10 b. The Result is : 5 c. The Result is : 20 d. Error

Back

d

Front

a. RMI application server runs on locahost. b. EJB web server runs on locahost. c. Add two properties. d. EJB application server runs on locahost.

Back

c

Front

Where the following code comes from the only servlet in a web application, what is the outcome of accessing the doGet() method? Choose one answer. a. Console output: "Is the session new? false" b. Compiling errors. c. Console output: "Is the session new? true Session invalidated" d. Console output: "Is the session new? true"

Back

c

Front

a. 1 b. 3 c. 4 d. 2

Back

b

Front

a. The code is compiled successfully b. The code will not compile and should be enclosed in a try-catch block c. None of the others. d. The onMessage() method may throw any application exception

Back

b

Front

a. The application will deploy basic login will take precedence over form login b. Some other validation error will occur; the application will not deploy c. None of the others. d. The application will deploy form login will take precedence over basic login

Back

b

Front

Choose one answer. a. http://host:port/FirstServlet;jsessionid=...&par=urlRewriting b. http://host:port/TerminalServlet;jsessionid=...?par=urlRewriting c. http://host:port/FirstServlet&jsessionid=...?par=urlRewriting d. None of the others.

Back

d

Front

What is the consequence of attempting to access the following JSP page? <html> <body> <%! public void _jspService(HttpServletRequest request, HttpServletResponse response) { out.write("A"); } %> <% out.write("B"); %> </body> </html> Choose one answer. a. "A" is output to the response before "B". b. "A" is output to the response. c. "B" is output to the response. d. Duplicate method compilation error.

Back

c

Front

a. Error(s). b. num1 c. 10 d. 0

Back

a

Front

Choose one answer. a. (1) b. (3) c. (2) d. None of the others.

Back

b

Front

Choose one answer. a. (2) b. None of the others. c. (3) d. (1)

Back

c

Front

a. No error and output is nothing. b. Sorry, no match value found c. Aptech JSP course d. Error

Back

b

Front

Choose one answer. a. The servlet causes 500 error code b. Get Session is Final Test c. The servlet throws the NullPointerException d. The servlet causes the error at the compiling time

Back

b

Front

a. Manager b. user, manager c. None of the others. d. Admin

Back

b

Front

Consider the following code fragment try { System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); System.setProperty("java.naming.provider.url", "localhost:1099"); Context ctx = new InitialContext(); Object ref = ctx.lookup("TestJNDI1"); CalculatorRemoteHome home = (CalculatorRemoteHome) PortableRemoteObject.narrow(ref, CalculatorRemoteHome.class); CalculatorRemote remote = home.create(); double dAdd = remote.add(9, 4.3); System.out.println("Add " + dAdd); remote.remove(); } catch(Exception e){ e.printStackTrace(); } Assuming the Stateless Session Bean implemented correctly with business method double add(double a, double b), that return the total of a and b, and it mapped JNDI with naming TestMapping, what will the output in the console? Choose one answer. a. None of the others. b. The error occurs "TestJNDI1 is not bound" c. The code causes errors because the 9 is not a double d. 13.3

Back

b

Front

a. Add a cookie with maximum age is 5 minutes. b. Add a persistent cookie with maximum age is 5 minutes. c. Add a temporary cookie with maximum age is 5 seconds. d. Add a persistent cookie with maximum age is 5 seconds.

Back

a

Front

a. The snippet code will cause a deploy-time error. b. The snippet code will cause a compile-time error. c. The snippet code will cause no error. d. The snippet code will cause a runtime error.

Back

b

Front

a. TestBean do not exist!!!!! b. Msg: 123 - 4 c. The code 500 error is present at browser d. The servlet code is invalid

Back

b

Front

Marks: 0.00/1.00 Consider the following code fragment of Local Interface and Local Home interface of Entity Bean public interface RegistrationLocal extends EJBLocalObject { public String getUsername(); public String getPassword(); public void setPassword(String password); public String getLastname(); public void setLastname(String lastname); public boolean isRoles(); public void setRoles(boolean roles); } public interface RegistrationLocalHome extends EJBLocalHome { sample.bmp.RegistrationLocal findByPrimaryKey(java.lang.String key) throws FinderException, RemoteException; RegistrationLocal create(String username, String password, String lastname, boolean roles) throws CreateException; Collection findByLikeUser(String name) throws FinderException; } Choose the correct answer Choose one answer. a. The code of Local Home interface is not invalid because the findByPrimaryKey method should not be declared b. The code of Local Home interface is not invalid because the findByPrimaryKey method throws the RemoteException c. All of the others. d. The code of Local interface is invalid because all of the methods must throw the RemoteException

Back

a

Front

<html> <body> <form action="loginPage.jsp"> Login ID:<input type= "text" name="loginID"><br> Password:<input type="password" name="password"><br> <input type="submit" value="Login"> <input type="reset" value="Reset"> </form> </body> <html> Study the above html code. Assume that user clicks button Reset. What is the correct statement? Choose one answer. a. All inputs are cleared. b. All inputs are submitted to server. c. Nothing change.

Back

a

Front

Marks: 0.00/1.00 What is output to the web page on the second access to the same instance of the following JSP? <html> <body> <% int x = 0; %> <%= x++ %> </body> </html> Choose one answer. a. 0 b. 2 c. 1 d. 3

Back

a

Front

a. Methods in a class extending the javax.ejb.EJBLocalHome class can not throw a RemoteException. b. Syntax error. c. The findByPrimaryKey() method can not throw any exception. d. The findByPrimaryKey() method can not throw FinderException.

Back

c

Front

Choose one answer. a. None of the others b. ${requestScope["foo"["advice"]]} c. ${requestScope.foo.advice} d. ${requestScope[foo[advice]]}

Back

c

Front

a. 4 6 45 b. 1 2 145 c. 4 6 451 d. 4 2 451

Back

c

Front

Marks: 0.00/1.00 What is the result of attempting to access the following JSP page? <html> <body> <%! public String methodA() { return methodB(); } %> <%! public String methodB() { return "JAD Final Test"; } %> <h2><%= methodA() %></h2> </body> </html> Choose one answer. a. A translation error occurs. b. The web page is blank. c. "JAD Final Test" is output to the resulting web page. d. A runtime error occurs.

Back

c

Front

a. The flush attribute must be false b. The keyword 'file' should be used instead of 'page' in the < jsp:forward/ > action. c. Actions cannot be used within scriptlet blocks. d. Unmatched bracket in for statement

Back

a

Front

a. All of the others. b. The line 13 cause the error at the runtime "The Date cannot be resolved to a type" c. The code is valid if the <%@ page import="java.util.Date" %> d. The code 500 error is present in the browser

Back

a

Front

a. The code is invalid because the method declaration is declared in scriptlet and the implicit object is declared in declaration b. The jsp output "This is a final test" and "The code is execute" on the server console c. The jsp output "This is a final test" on the server console and output "The code is execute" on the browser d. All of the others.

Back

d

Front

For what reason does the following JSP fail to translate and compile? <html> <body> <%! int x; %> <% public String getDescription() { return "JAD Final Test"; } %> <%=getDescription() %> </body> </html> Choose one answer. a. The page actually compiles and translates without any problem. b. Expression embedded in declaration. c. Local variable x not initialized before use. d. Method declared in scriptlet. e. Data member x not initialized before use.

Back

a

Front

a. First run standard output produced "The session musician is: null"; second run-standard output produced "The session musician is: null" b. First run standard output produced "The session musician is: "; second run-standard output produced "The session musician is: Eric Dolphy" c. First run standard output produced "The session musician is: "; second run-standard output produced "The session musician is: " d. First run standard output produced "The session musician is: null"; second run-standard output produced "The session musician is: Eric Dolphy"

Back

c

Front

a. Compiling errors b. Ignores the redirect and outputs "OneTwo" to the response c. Redirects to the abcServlet d. Writes "One" to the response; errors at the redirect

Back

a

Front

What will be outcome of running the following servlet code for the given deployment descriptor file? Choose one answer. a. Output: 1a1a2 b. Output: 1a2 c. All of the others. d. Output: 1a21a

Back

d

Front

a. The page causes a compile-time error. b. The page has no error and will display some information. c. The page causes a runtime error and will display a lot of error messages. d. The page causes a runtime error and will call the page "error.jsp" to handler this error.

Back

c

Front

a. Name testFinal - b. Name testFinal - 20 c. ${myEL:displayInfos("testFinal", 20)} d. The jsp run errors due to the tlb file invalid

Back

c

Front

a. The request object is used for creating cookies. b. Cookie class can not take parameters in it's constructor. c. Although no error will be reported the use of the <jsp:include/> action means that the response object can't be used to create cookies. d. The <jsp:include/> action must be placed inside the script block.

Back

c

Front

Choose one answer. a. The code causes the error at the compiling time b. initialize: 6 fake: null c. initialize: 5 fake: null d. The code causes the error at the running time

Back

c

Front

Given the following onMessage() method of a MDB: (Assume that all necessary imports have been made, that Bean is the component interface type of a stateless session bean and Bean Home is its home interface) Choose one answer. a. The code causes errors when it is compiled. b. None of the other. c. The code is compiled successfully.

Back

b

Front

a. 2 : value1 and value2 b. 3: value1,value2 and sum c. 2 : val1 and val2 d. 3: val1,val2 and sum

Back

Section 2

(50 cards)

a

Front

Following is the code for doGet() and doPost() method of TestServlet. Which of the statement is correct? Choose one answer. a. This will work for HTTP GET as well as POST requests. b. This will only work for HTTP POST requests c. It'll throw an exception at runtime only if a POST request is sent to it. d. It'll throw an exception at runtime, as you cannot call doGet() from doPost(). e. This will only work for HTTP GET requests

Back

b

Front

Marks: 0.00/1.00 Consider the following html fragment and code fragment - html fragment <form action="MyServlet" method="GET"> <input type="text" name="foo"> <input type="text" name="foo"> <input type="submit"> </form> - MyServlet code fragment 8. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 9. String first = request.getParameter("foo"); 10. String second = request.getParameter("foo"); 11. out.println("The result are " + first + " - " + second) 12. } What is the output from MyServlet code? Assuming that the user input "first" into the first control and "second" in the second control Choose one answer. a. The result are first - second b. The result are first - first c. The result are second - second d. The result are second - first

Back

c

Front

Marks: 0.00/1.00 <html> <body> <form action="loginPage.jsp"> Login ID:<input type= "text" name="loginID"><br> Password:<input type="password" name="password"><br> <input type="submit" value="Login"> <input type="reset" value="Reset"> </form> </body> <html> Study the above html code. Assume that user clicks button Login. What are the correct statements. Choose one answer. a. The value of 02 text inputs appended to the requested URL. b. The form intputs are submitted by GET method. c. All of the others. d. The loginPage.jsp is called.

Back

a

Front

Marks: 0.00/1.00 Given: 1. //insert code 2. ... 3. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 4. PrintWriter out = response.getWriter(); 5. out.println ("Hello"); 7. } Which statement at line 1 allows this code to compile and run? Choose one answer. a. import java.io.PrintWriter; b. #include java.io.PrintWriter; c. #include java.io.OutputStream Writer; d. import java.io.OutputStreamWriter;

Back

b

Front

Given: 10. public void service (HttpServletRequest request, 11. HttpServletResponse response) { 12. // your code here 13.} Which code snippet inserted at line 12 cause the client to forward the request object to http://www.example.com? Choose one answer. a. RequestDispatch rd= getRequestDispatcher(new URL ("http://www.example.com")); rd. include (request.response); b. RequestDispatcher rd = request.getRequestDispatcher ("http://www.example.com"); rd.forward(request, response); c. http://www.example.com; d. response.send Redirect (new URL ("http://www.example.com"));

Back

c

Front

What is the result of attempting to access the following JSP page? <html> <body> <%! public String methodA() { return methodB(); } %> <%! public String methodB() { return "JAD Final Test"; } %> <h2><%= methodA() %></h2> </body> </html> Choose one answer. a. A translation error occurs. b. The web page is blank. c. "JAD Final Test" is output to the resulting web page. d. A runtime error occurs.

Back

d

Front

Given: 1. <% String value ="beanValue"; %> 2. <%request.setAttribute("com.example.bean", value); %> 3. <%-- insert code here --%> Which EL expression, inserted at line 3, is valid and evaluates to "beanValue"? Choose one answer. a. ${bean} b. ${value} c. ${request.get("com.example.bean").toString()} d. ${requestScope['com.example.bean']}

Back

d

Front

A JSP page called test.jsp is passed a parameter name in the URL using http://localhost/test.jsp?name="John". The test.jsp contains the following code. <%! String myName=request.getParameter();%> <% String test= "welcome" + myName; %> <%= test%> What is the output? Choose one answer. a. The program prints "Welcome John" b. The program gives a syntax error because of the statement <%= test%> c. The program gives a syntax error because of the statement <% String test= "welcome" + myName; %> d. The program gives a syntax error because of the statement <%! String myName=request.getParameter();%>

Back

c

Front

Marks: 0.00/1.00 Given: 5. public class MyTagHandler extends TagSupport { 6. public int doStartTag() throws JspException { 7. try { 8. // insert code here 9. } catch(Exception ex) { / handle exception / } 10. return super.doStartTag(); 11. } ... 42. } Which code snippet, inserted at line 8, causes the value foo to be output? Choose one answer. a. print("foo"); b. JspWriter w = new JspWriter(pageContext.getWriter()); c. JspWriter w = pageContext.getOut(); d. JspWriter w = pageContext.getWriter();

Back

b

Front

Given The JSP page code snippet: 1. <jsp:useBean id='product'> 2. <jsp:setProperty name='product' property='price' value='49.95'/> 3. </jsp:useBean> 4. <%= product.getName() %> costs <%= product.getPrice() %> The Java Bean code fragment package com.example public class Product { private String name; private double price; public Product() { this("Default", 0.0); } public Product(String name, double price) { this.name = name; this.price = price; } public String getName(){ return name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } } What is the response output of this JSP page code snippet? Choose one answer. a. Default costs 0.0 b. Default costs 49.95 c. 49.95 costs 49.95 d. product costs 0.0

Back

c

Front

Given: 10. public void service (HttpServletRequest request, 11. HttpServletResponse response) { 12. // your code here 13.} Which code snippet inserted at line 12 cause the client to redirect to http://www.example.com? Choose one answer. a. response.send Redirect (new URL ("http://www.example.com")); b. RequestDispatch rd= getServletContext().getRequestDispatcher(new URL ("http://www.example.com")); rd. forward (request.response); c. response.sendRedirect ("http://www.example.com"); d. RequestDispatcher rd= getServletContext ().getRequestDispatcher ("http://www.example.com"); rd. forward (request, response);

Back

a

Front

Marks: 0.00/1.00 Assume that you need to write a JSP page that adds numbers from one to ten, and then print the output. <% int sum = 0; for(j = 0; j < 10; j++) { %> // XXX --- Add j to sum <% } %> // YYY --- Display the sum Which statement when placed at the location XXX can be used to compute the sum. Select the one correct statement Choose one answer. a. <% sum = sum + j; %> b. <%= sum = sum + j %> c. <%= sum = sum + j; %> d. <% sum = sum + j %>

Back

d

Front

Given a servlet OrderServlet mapped to processorder. And a form declaration in HTML: 11. <form action = "processorder"> 12. <input type="text" name="first_name"/> 13. <input type="text" name = "last_name"/> 14. <input type= "submit" value = "Submit Order"/> 15. </form> What OrderServlet method is invoked as a result of this from submission? Choose one answer. a. doPost b. doSubmit c. doPut d. doGet

Back

d

Front

Marks: 0.00/1.00 For what reason does the following JSP fail to translate and compile? <html> <body> <%! int x; %> <% public String getDescription() { return "JAD Final Test"; } %> <%=getDescription() %> </body> </html> Choose one answer. a. Expression embedded in declaration. b. Data member x not initialized before use. c. Local variable x not initialized before use. d. Method declared in scriptlet. e. The page actually compiles and translates without any problem.

Back

c

Front

For what reason does the following JSP fail to translate and compile? <html> <body> <%! int x; %> <%=x ; %> </body> </html> Choose one answer. a. Local variable x not initialized before use. b. Method declared in scriptlet. c. Error in JSP Expression. d. Data member x not initialized before use.

Back

c

Front

You are developing an Human Resource application with the following requirements: Users access the systems over an intranet, using a standard Web browser. Organization information is stored in LDAP. Benefits information is stored in an RDBMS. Complaints are sent directly to a third-party system for compliance. Which J2EE technology would allow the system to interact with the LDAP server? Choose one answer. a. JMS b. JDBC c. JNDI d. JSP

Back

a

Front

What will be the outcome of executing the following code? public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain"); response.setContentLength(6); PrintWriter out = response.getWriter(); out.write("What's your name? "); out.write("" + response.isCommitted()); } Choose one answer. a. "What's" is returned to the client. b. An IllegalArgumentException is thrown. c. A blank page is returned to the client. d. An IllegalStateException is thrown. e. Won't execute because of a compilation error. f. "What's your name?" is returned to the client.

Back

a

Front

Given: 4. first = home.create(); 5. second = home.create(); 6. result = first.isIdentical(second); Assume home is a valid reference to a session object's home interface, and all values have been properly declared. Which statements are true about the value of result? Choose one answer. a. All of the others b. If both beans are stateful, result is always false. c. If both beans are stateless, result is always true.

Back

c

Front

Which defines the welcome files in a web application deployment descriptor? 1. <welcome-file-list> <welcome-file>welcome.jsp</welcome-file> <welcome-file>index.html</welcome-file> </welcome-file-list> 2. <welcome> <welcome-file>welcome.jsp</welcome-file> </welcome> <welcome> <welcome-file>index.html</welcome-file> </welcome> 3. <welcome> <welcome-file>/welcome.jsp</welcome-file> </welcome> <welcome> <welcome-file>/index.html</welcome-file> </welcome> Choose one answer. a. 2, 3 b. 1, 2 c. Only 1 d. All of the others

Back

c

Front

Marks: 0.00/1.00 Consider the following html fragment and code fragment - html fragment <form action="MyServlet" method="GET"> <input type="text" name="foo"> <input type="text" name="foo"> <input type="submit"> </form> - MyServlet code fragment 8. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 9. String first = request.getParameter("foo"); 10. String second; 11. //insert code here 12. } Which statement, inserted at line 11 in MyServlet, retrieves the text form the second text field? Choose one answer. a. second =request.getParameter("foo", 1); b. second =request.getParameter("foo"); c. second =request.getParameterValues("foo")[1]; d. second =request.getParameters("foo")[1];

Back

d

Front

<html> <body> <form action="loginPage.jsp"> Login ID:<input type= "text" name="loginID"><br> Password:<input type="password" name="password"><br> <input type="submit" value="Login"> <input type="reset" value="Reset"> </form> </body> <html> Study the above html code. Assume that user clicks button Login. Which is the correct statement? Choose one answer. a. The value of two text inputs appended to the requested URL. b. The loginPage.jsp is called. c. The form intputs are submitted by GET method. d. All of the others

Back

d

Front

Given this code for an entity bean: private boolean insertAccount(String username, String password, String lastname, boolean roles) { try { Connection con = makeConnection(); String sql = "Insert into tbl_Final(id, field1, field2, field3) " + "values(?, ?, ?, ?)"; PreparedStatement stm = con.prepareStatement(sql); stm.setString(1, username); stm.setString(2, password); stm.setString(3, lastname); stm.setBoolean(4, roles); int rows = stm.executeUpdate(); stm.close(); con.close(); if (rows > 0) { return true; } return false; } catch (Exception e) { throw new EJBException("Insert errors: " + e.getMessage()); } } Which statement is true? Choose one answer. a. The method should be put in the ejbStore method in BMP b. The method should be put in the unsetEntity context method in BMP c. The method should be put in the ejbPassivate method in BMP d. The method should be put in the ejbCreate method in BMP

Back

a

Front

Given the following deployment descriptor: <web-app> <servlet> <servlet-name>InitParams</servlet-name> <servlet-class>com.osborne.c02.InitParamsServlet</servlet-class> <init-param> <param-name>initParm</param-name> <param-value>Final Test</param-value> </init-param> </servlet> </web-app> What is the outcome of running the following servlet? public class InitParamsServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext sc = this.getServletContext(); PrintWriter out = response.getWriter(); out.write("Initialization Parameter is: " + sc.getInitParameter("initParm")); } } Choose one answer. a. "Initialization Parameter is: null" returned to the requester b. "Initialization Parameter is: Final Test" returned to the requester c. A runtime error d. "Initialization Parameter is: null" written to the console

Back

b

Front

Given this code for an entity bean: public interface EmployeeHome extends javax.ejb.EJBHome { // more code public float livingIndex(String state, float salary) throw java.rmi.RemoteException; // more code } Which statement is true? Choose one answer. a. The method name livingIndex is illegal. b. The method livingIndex is EJB 2.0 compliant. c. The method livingIndex must throw an additional required exception. d. The method livingIndex is prohibited from throwing RemoteException.

Back

d

Front

Given a servlet OrderServlet mapped to processorder. And a form declaration in HTML: 11. <form action = "processorder" method="post"> 12. <input type="text" name="first_name"/> 13. <input type="text" name = "last_name"/> 14. <input type= "submit" value = "Submit Order"/> 15. </form> What OrderServlet method is invoked as a result of this from submission? Choose one answer. a. doGet b. doSubmit c. doFilter d. doPost

Back

a

Front

A JSP page called test.jsp is passed a parameter name in the URL using http://localhost/Final/test.jsp?name=John. The test.jsp contains the following code. <% String myName=request.getParameter("name");%> <% String test= "Welcome " + myName; %> <%=test%> What is the output? Choose one answer. a. The page displays "Welcome John" b. The program gives a syntax error because of the statement <%=test%> c. The program gives a syntax error because of the statement <% String test= "Welcome " + myName; %> d. The program gives a syntax error because of the statement <% String myName=request.getParameter("name");%>

Back

c

Front

Marks: 0.00/1.00 Given an HttpServletRequest request 22. String id =request.getParameter("jsessionid"); 23. //insert code here 24. String name = (String) session.getAttribute("name"); Which of the following statements can be placed at line 23 to retrieve an existing HttpSession object? Choose one answer. a. HttpSession session = request.getSession(); b. HttpSession session = request.getSession(true); c. All of the others d. HttpSession session = request.getSession(false);

Back

b

Front

What will be the outcome of executing the following code? public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain"); response.setContentLength(6); PrintWriter out = response.getWriter(); out.write("What's your name? "); out.write("" + response.isCommitted()); } Choose one answer. a. An IllegalStateException is thrown. b. "What's" is returned to the client. c. "What's your name?" is returned to the client. d. Won't execute because of a compilation error. e. A blank page is returned to the client. f. An IllegalArgumentException is thrown.

Back

d

Front

Marks: 0.00/1.00 Given: What is the output from the following JSP page? Assume that the following url: http://localhost:8080/finalExam/index.jsp?x=1&y=2 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <c:set var="x" value="${param.x}"/> <c:set var="y" value="${param.y}"/> <c:set var="result" value="${x*y}"/> ${result} Choose one answer. a. "" b. null c. ${result} d. 2

Back

d

Front

Marks: 0.00/1.00 Given: - web.xml fragment <servlet> <servlet-name>Controller</servlet-name> <servlet-class>sample.web.Controller</servlet-class> </servlet> <servlet-mapping> <servlet-name>Controller</servlet-name> <url-pattern>/ControllerURL</url-pattern> </servlet-mapping> The user should type "http://localhost:8084/__________" into the url address of web browser to call the Controller servlet. Choose one answer. a. Controller b. sample/web/Controller c. sample/web/ControllerURL d. ControllerURL

Back

b

Front

Marks: 0.00/1.00 Given the security constraint in a DD: 101. <security-constraint> 102. <web-resource-collection> 103. <web-resource-name>Foo</web-resource-name> 104. <url-pattern>/Bar/Baz/*</url-pattern> 105. <http-method>POST</http-method> 106. </web-resource-collection> 107. <auth-constraint> 108. <role-name>DEVELOPER</role-name> 109. </auth-constraint> 110. </security-constraint> And given that "MANAGER" is a valid role-name, which is true for this security constraint? Choose one answer. a. DEVELOPER cannot do a POST on resources in the /Bar/Baz directory. b. MANAGER can do a GET on resources in the /Bar/Baz directory. c. None of the others

Back

b

Front

What is the output from the following JSP? <%! Integer num = new Integer(7); %> A: ${num} B: <%= num %> <% Integer num = new Integer(6); request.setAttribute("num", num); %> C: ${num} Choose one answer. a. A: 7B: 7C: 6 b. A: B: 7C: 6 c. A: B: 6C: 6 d. A: 6B: 7C: 6

Back

b

Front

Given the following deployment descriptor: <web-app> <servlet> <servlet-name>InitParams</servlet-name> <servlet-class>com.osborne.c02.InitParamsServlet</servlet-class> <init-param> <param-name>initParm</param-name> <param-value>Final Test</param-value> </init-param> </servlet> </web-app> What is the outcome of running the following servlet? public class InitParamsServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext sc = this.getServletContext(); PrintWriter out = response.getWriter(); out.write("Initialization Parameter is: " + sc.getInitParameter("initParm")); } } Choose one answer. a. "Initialization Parameter is: null" written to the console b. "Initialization Parameter is: null" returned to the requester c. "Initialization Parameter is: Final Test" returned to the requester d. A runtime error

Back

d

Front

Marks: 0.00/1.00 A developer has used this code within a servlet: 62. if(request.isUserInRole("vip")) { 63. // VIP-related logic here 64. } What else must the developer do to ensure that the intended security goal is achieved? Choose one answer. a. define a group within the security realm and call it vip b. define a security-role named vip in the deployment descriptor c. create a user called vip in the security realm d. declare a security-role-ref for vip in the deployment descriptor

Back

b

Front

Marks: 0.00/1.00 <html> <body> <form action="loginPage.jsp"> Login ID:<input type= "text" name="loginID"><br> Password:<input type="password" name="password"><br> <input type="submit" value="Login"> <input type="reset" value="Reset"> </form> </body> <html> Study the above html code. Assume that user clicks button Reset. What is the correct statement? Choose one answer. a. All inputs are submitted to server. b. All inputs are cleared. c. Nothing changes.

Back

a

Front

What will be the output from accessing the index.jsp with the following url: http://localhost:8080/finalExam/index.jsp?X=1&Y=2 - index.jsp fragment <jsp:forward page="included.jsp"> <jsp:param name="X" value="4" /> <jsp:param name="X" value="5" /> <jsp:param name="Y" value="6" /> </jsp:forward> - included.jsp fragment ${param.X} ${param.Y} <% String[]x = request.getParameterValues("X"); for(int i=0; i<x.length; i++) { out.write(x[i]); } %> Choose one answer. a. 4 6 451 b. 4 6 4 c. 1 2 145 1 2 d. 4 5 6

Back

b

Front

Given JavaBean code fragment package com.example; public class Advisor { private String advice="take out the garbage"; public String getAdvice() { return advice; } public void setAdvice(String advice) { this.advice = advice; } } Jsp code fragment <% com.example.Advisor advisor = new com.example.Advisor(); request.setAttribute("foo", advisor); %> Choose one answer. a. ${requestScope["foo"]["advice"]} b. All of the others c. ${foo.advice} d. ${requestScope.foo.advice}

Back

a

Front

Given the web application deployment descriptor element: <context-param> <param-name>foo</param-name> <param-value>sushi</param-value> </context-param> Which retrieves the value associated with "foo" from within an HttpServlet? Choose one answer. a. String value = getServletContext().getInitParameter("foo"); b. String value = getServletConfig().getParameter("foo"); c. Object value = getServletConfig().getInitParameter("foo"); d. String value = getServletContext().getAttribute("foo");

Back

c

Front

Given the following JSP and tag handler code, what is the result of accessing the JSP? JSP Page Source <html> <body> <%@taglib uri="test_taglib" prefix="myTag"%> <% session.setAttribute("first", "first"); %> <myTag:TestTag/> <br> <%=session.getAttribute("second")%> </body> </html> Tag Handler Code for <myTag:TestTag /> package examples; import java.io.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; public class TestTag extends TagSupport { private PageContext pageContext; public void setPageContext(PageContext page){ this.pageContext=page; } public int doStartTag() throws JspException { try{ String first=pageContext.getSession().getAttribute("first").toString(); pageContext.getOut().write(first); pageContext.setAttribute("second", "second",PageContext.PAGE_SCOPE); } catch(IOException i) { throw new JspException(i.getMessage()); } return SKIP_BODY; } public int doEndTag() throws JspException { return EVAL_PAGE; } public void release() { } } Assume *.tld and web.xml files are correct. Choose one answer. a. first second b. second null c. first null d. second first

Back

c

Front

Marks: 0.00/1.00 What will be the result of pressing the submit button in the following HTML form? <form action="/servlet/Register"> <input type="text" name="fullName" value="Type name here" /> <input type="submit" name="sbmButton" value="OK" /> </form> Choose one answer. a. The parameter fullName is the only parameter passed to the web server as part of the request body. b. A request is sent with the HTTP method POST. c. A request is sent with the HTTP method GET. d. A request is sent with the HTTP method HEAD. e. The parameter fullName is the only parameter passed to the web server in the request URL.

Back

d

Front

Given: String value = getServletContext().GetInitParameter("foo"): in an HttpServlet and a web application deployment descriptor that contains: <context-param> <param-name>foo</param-name> <param-value>frodo</value> <context-param> Which are true? Choose one answer. a. The foo parameter must de defined within the element of the deployment descriptor. b. Compilation fails because ServletContext does NOT have a getInitParameter method. c. Compilation fails because getInitParameter returns type Object. d. The foo initialization parameter CANNOT be set programmatically.

Back

d

Front

Marks: 0.00/1.00 Consider the following HTML page code. Which method will be called on UploaderServlet when a user clicks on the submit button displayed by the above page? Choose one answer. a. doPut b. doPost c. doHead d. doGet

Back

c

Front

What is output to the web page on the second access to the same instance of the following JSP? <html> <body> <% int x = 0; %> <%= x++ %> </body> </html> Choose one answer. a. 1 b. 2 c. 0 d. 3

Back

d

Front

What will be outcome of running the following servlet code for the given deployment descriptor file? - Servlet code protect void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletConfig config = getServletConfig(); String oneA = config.getInitParameter("first"); String oneB = config.getInitParameter("first"); String two = config.getInitParameter("two"); PrintWriter out = response.getWriter(); out.write(oneA + oneB + two); } - web.xml fragment <context-param> <param-name>first</param-name> <param-value>1a</param-value> </context-param> <context-param> <param-name>first</param-name> <param-value>1b</param-value> </context-param> <context-param> <param-name>second</param-name> <param-value>2</param-value> </context-param> Choose one answer. a. 1a1a2 b. 1a1b2 c. nullnullnull d. None of the others

Back

a

Front

Which ensures that a JSP response is of type "text/plain"? A. <%@ page mimeType="text/plain" %> B. <%@ page contentType="text/plain" %> C. <%@ page pageEncoding="text/plain" %> D. <%@ page contentEncoding="text/plain" %> Choose one answer. a. Only B b. A, B c. C, D d. All of the others

Back

c

Front

Marks: 0.00/1.00 What is output to the web page on the second access to the same instance of the following JSP? <html> <body> <%! int x = 0; %> <%= x++ %> </body> </html> Choose one answer. a. 3 b. 2 c. 1 d. 0

Back

a

Front

Given the web application deployment descriptor element: <servlet> <servlet-name>ConfigServlet</servlet-name> <servlet-class>sample.servlet.ConfigServlet</servlet-class> <init-param> <param-name>foo</param-name> <param-value>1000</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>ConfigServlet</servlet-name> <url-pattern>/ConfigServlet</url-pattern> </servlet-mapping> Which retrieves the value associated with "foo" from within a init(ServletConfig config) method of an HttpServlet? Choose one answer. a. String value = config.getInitParameter("foo"); b. String value = getServletContext().getInitParameter ("foo"); c. String value = response.getParameter("foo"); d. String value = request.getParameter("foo");

Back

d

Front

Which defines the welcome files to access the servlet in a web application deployment descriptor? Assume that the user type the url on address bar of web browser as http://localhost:8084/myFinalApp/ - web.xml fragment <servlet> <servlet-name>Controller</servlet-name> <servlet-class>sample.web.Controller</servlet-class> </servlet> <servlet-mapping> <servlet-name>Controller</servlet-name> <url-pattern>/ControllerURL</url-pattern> </servlet-mapping> 1. <welcome-file-list> <welcome-file>ControllerURL</welcome-file> </welcome-file-list> 2. <welcome> <welcome-file>/ControllerURL</welcome-file> </welcome> 3. <welcome> <welcome-file>/Controller</welcome-file> </welcome> 4. <welcome> <welcome-file>Controller</welcome-file> </welcome> Choose one answer. a. 2,3 b. 1, 2 c. All of the others d. Only 1

Back

b

Front

Marks: 0.00/1.00 A web application uses the HttpSession mechanism to determine if a user in "logged in". When a user supplies a valid username and password, an HttpSession is created for that user. The user has access to the application for only 15 minutes after logging in. The code must determine how long the user has been logged in, and if this time is greater than 15 minutes, must destroy the HttpSession Which method in HttpSession is used to accomplish this? Choose one answer. a. invalidateAfter b. getCreationTime c. getMaxInactiveInterval d. getLastAccessedTime

Back

d

Front

What will be the result of pressing the submit button in the following HTML form? <form action="/servlet/Register"> <input type="text" name="fullName" value="Type name here" /> <input type="submit" name="sbmButton" value="OK" /> </form> Choose one answer. a. A request is sent with the HTTP method POST. b. The parameter fullName is the only parameter passed to the web server as part of the request body. c. A request is sent with the HTTP method HEAD. d. A request is sent with the HTTP method GET. e. d. The parameter fullName is the only parameter passed to the web server in the request URL.

Back

Section 3

(1 card)

d

Front

A bean with a property color is loaded using the following statement <jsp:usebean id="fruit" What happens when the following statement is executed? Select the one correct answer. <jsp:setProperty name="fruit" property="*"/> Choose one answer. a. All the properties of the fruit bean are initialized to a value of null. b. This is incorrect syntax of and will generate a compilation error. Either value or param must be defined. c. All the properties of the fruit bean are initialized to a value of *. d. All the properties of the fruit bean are assigned the values of input parameters of the JSP page that have the same name.

Back