Sie sind auf Seite 1von 7

1. HttpSession s = request.

getSession();
s.setMaxInactiveInterval(0);
if(s.isNew()){
System.out.println("new session");
}
else{
System.out.println("something else");
}

Predict the output

2. Which is right.,(choose two)

a There is one ServletConfig object per servlet


b There is one ServletConfig object per application
c There is one ServletContext object per servlet
d There is one ServletContext per application

3. Which is right.,(choose two)

a. There is one ServletConfig object per servlet


b. There is one ServletConfig object per application
c. There is one ServletContext object per servlet
d. There is one ServletContext per application

4. Which of these are implicit objects (choose more than one)

a. pageContext
b. requestScope
c. request
d. exception

5. Which of these are valid ways of setting the Integer attribute value of 10
to the empId attribute of the employee bean. Assume that there is an
empId parameter bound to the request with the value 10(Choose more than one)

a. <jsp:setProperty name=employee property=*/>


b. <jsp:setProperty name=employee param=empId/>
c. <jsp:setProperty name=employee property=empId/>
(Another option that I dont remember)

6. To which of these objects can you set attributes to(Choose more than one)

a. Session
b. ServletContext
c. ServletConfig
d. Request

7. Which listener do you use to find out if the session is persisted


a. HttpSessionListener
b. HttpSessionAttributeListener
c. ServletContextListener
d. ServletContextAttributeListener

8. Which of these are valid JSP expressions(Choose more than one)

a. <%= (2*3) %>


b. <%= (2*3) ; %>
c. <%= 3>5 %>
d. <%= 2*3 >

9. If cookies are disabled, which of the following approaches you use to keep
track of sessions

a. Manually append sessionId=${session.getId()} to the URL


b. Encode the URL
(Two more options that I dont remember)

10. Which one of the following do you use to redirect to an error page

a. response.sendRedirect(URL);
b. response.sendErrorRedirect(URL);
c. response.setStatus(ErrorStatusCode);
d. response.sendStatus(ErrorStatusCode);

11. Line 1 : <%! int a = 5; %>

Line 2 : <% a = 6; %>

Line 3 : <% b = 5; %>

Line 4 : <%= a*b; %>

a. Error in Line 2
b. Output 25
c. Output 30
d. Error in Line 4

12. There are two custom tags t1 and t2. T1 is associated with a tag handler
class that implements BodyTagSupport and T2 is associated with a tag handler
class that implements SimpleTagSupport. It is known that both the tags have a
body. Which of these is a valid way of using these tags in a JSP?
a. <prefix:t1><prefix:t2>aaaa</prefix:t2></prefix:t1>
b. <prefix:t1/><prefix:t2/>
c. <prefix:t1><prefix:t2/></prefix:t1>
d. <prefix:t1><prefix:t2></prefix:t1></prefix:t2>

13. Listeners are registered

a. In the deployment descriptor


b. In the listener class
(Other options which I cant recollect)

14. What is the solution if cookies are disabled by the browser

a. Add cookie only


b. Rewrite URL and add cookie
c. Rewrite URL only, dont add cookie
d. None of the above

15. The service() method is

a. Always overridden
b. Never overridden
c. Generally overridden
d. None of these

16. Which of the following is true(Choose more than one)

a. A JSP can service a request by itself


b. A servlet can service a request by itself
c. A JSP needs the help of a servlet to service a request
d. A servlet needs the help of a JSP to service a request

17. Which of the following is a valid way to access context-init parameters

a. ${context.init[paramName]}
b. ${initParam.paramName}
c. ${initParam[paramName]}
d. ${paramName}
(Not sure of the options)

18. <init-param>

<param-name>Param</param-name>
</param-value>Value</param-value>

</init-param>

How do you access this parameter

a. getServletContext().getServletConfig().getInitParameter(Param);
b. getServletConfig().getServletContext().getInitParameter(Param);
c. request.getServletContext().getInitParameter(Param);
d. session.getServletConfig().getInitParameter(Param);

19. Which of these is used to invalidate a session?

a. <invalidate-session>
b. <session-stop>
c. <session-timeout>
d. None of these

20. What is the purpose of a JSP expression?

a. To execute a block of Java code


b. To print something
c. To declare objects
d. None of these

21. Which among these is a C-tag alternative for the Switch-case block?

a. <c:when>
b. <c:if>
c. <c:out>
d. There is no C-tag alternative for switch-case

22. Which of these is used to invalidate a session?

a. <invalidate-session>
b. <session-stop>

23. Which of these is valid?

a. $[map.key]
b. $[map[key]}
c. $[map[names[0]]}

24. By default, what is the scope of ServletContext and Cookies

a. Application
b. Page

25. Which of these is a valid way to set an attribute to a session?(Choose


two)

a. Session.setAttribute(var,abc);
b. Session.setAttribute(var, new Long(abc));
c. Session.setLongAttribute(var,abc);
d. Session.setLongAttribute(var, new Long(abc));

26. Which of these can be used to collect and store user information?

a. request
b. session
c. pageContext

27. Which listener would you use to listen to the creation of a new session?

a. HttpSessionListener
b. HttpSessionAttributeListener
c. ServletContextListener
d. None of these

28. Which attribute is used to check a condition in the <c:if> tag?

a. check
b. test
c. expression
d. condition

29. What action must be performed for a Servlet to perform the role of an
HttpServlet

a. Use doXXX methods(doPost, doGet, doOptions)

30. <%! int a = 5 %>

<% b = 3 %>

<% a = 3 %>

<%= a*b %>

What is the output of the above code


a. 9
b. 15
c. 25
d. Compilation error

31. How to get the parameters defined in an application scope

a. request.getParameter()
b. request.getCookies()
c. session.getParameter()
d. None of these

32. The compilation and the initialization of the jsp is done in which phase?

a. Deployment phase
b. Build phase
c. Translation phase
d. None of these

33. Which of the following are valid ways to invalidate a session?(Choose more
than one)

a. <%@ page session = x secs %>


b. <%@ page session= x minutes%>
c. session.invalidate(x secs);

34. Which object can invalidate a session?

a. application
b. context
c. page
d. session

35. What are the features not supported by the web container

a. Compiling JSPs
b. Multithreading
c. Compiling servlets
d. None of these

Das könnte Ihnen auch gefallen