Computer Knowledge
Java Enterprise and Web Technologies
2,183 Questions
Java enterprise and web technologies questions focus on J2EE architecture, web services like SOAP, and servlet functionalities. These topics frequently appear in IT officer and specialist scale examinations. Regular practice ensures familiarity with enterprise application components.
HttpServlet methodsSOAP and web servicesEJB architecture rolesJ2EE componentsJSP servlet callingUDDI concepts
Java Enterprise and Web Technologies Questions
-
out
-
session
-
request
-
response
-
httpsession
-
page
E
Correct answer
Explanation
JSP provides implicit objects like out, request, response, session, and page that can be used directly in expressions. 'httpsession' is not a valid JSP implicit variable - the session object itself is an HttpSession, not a variable called 'httpsession'. Options A, B, C, D, and F are all standard implicit objects available in JSP expressions.
-
G. <jsp:usebean id="fruit scope ="page"/>
-
H. <jsp:usebean id="fruit type ="String"/>
-
I. <jsp:usebean id="fruit type ="String" beanName="Fruit"/>
-
J. <jsp:usebean id="fruit class="Fruit" beanName="Fruit"/>
B,C
Correct answer
Explanation
The action requires either a class or type attribute. Option B correctly uses only the type attribute with proper syntax. Option C is also valid as it combines type with beanName (used with type but not class). Option A has malformed scope attribute (missing equals), and option D incorrectly combines class with beanName which are mutually exclusive alternatives.
-
A. The getRequestDispatcher method of ServletContext class takes the full path of the servlet, whereas the getRequestDispatcher method of HttpServletRequest class takes the path of the servlet relative to the ServletContext.
-
B. The include method defined in the RequestDispatcher class can be used to access one servlet from another. But it can be invoked only if no output has been sent to the server.
-
C. The getRequestDispatcher(String URL) is defined in both ServletContext and HttpServletRequest method
-
D. The getNamedDispatcher(String) defined in HttpServletRequest class takes the name of the servlet and returns an object of RequestDispatcher class.
A,C
Correct answer
Explanation
Option A correctly states that ServletContext.getRequestDispatcher uses full paths (starting with '/'), while HttpServletRequest.getRequestDispatcher uses paths relative to the current context. Option C is also correct - both interfaces define getRequestDispatcher with different path resolution rules. Option B is incorrect because include can be invoked after output. Option D is wrong because getNamedDispatcher is in ServletContext, not HttpServletRequest.
-
/META-INF/classes
-
/classes
-
/WEB-INF/classes
-
/root/classes
C
Correct answer
Explanation
In a WAR file, compiled Java classes must be placed in the WEB-INF/classes directory, maintaining their package structure. Options A, B, and D do not follow the WAR specification. The WEB-INF directory contains private resources that cannot be directly accessed by clients, making it the correct location for class files.
-
<f:faces>
-
<f:view>
-
<h:jsf>
-
<h:view>
B
Correct answer
Explanation
To solve this question, the user needs to have knowledge of JavaServer Faces (JSF) and its structure.
The correct answer is:
B.
The tag must enclose all other tags on a Faces JSP page. It represents the outermost container for a JavaServer Faces (JSF) application and is used to define the view that is to be rendered.
Option A, , is not a valid JSF tag.
Option C, , is not a valid JSF tag either.
Option D, , is a valid JSF tag, but it is not the correct answer to this question. The correct tag is .
-
To keep track of its identifier
-
To keep track of the components in tree
-
To set its submitted property
-
For JavaScript integration
C
Correct answer
Explanation
The HtmlForm component in JSF renders a hidden field to track its submitted state during the request processing lifecycle. This hidden field helps JSF determine whether the form has been submitted and distinguishes between initial form display and postback requests. The hidden field is not for tracking identifiers (A), component trees (B), or JavaScript integration (D) - those are handled by other JSF mechanisms.
-
#{contextPath}
-
#{requestContextPath}
-
#{facesContext.externalContext.requestContextPath}
-
${request.contextPath}
C
Correct answer
Explanation
In JSF, the full expression #{facesContext.externalContext.requestContextPath} accesses the external context to retrieve the request’s context path, which is the correct way to reference the application’s base URL. The other shorter forms either reference non‑existent properties or use the wrong EL syntax, making them incorrect.
-
doGet()
-
doTrace()
-
doOptions()
-
All the Above
D
Correct answer
Explanation
HttpServlet class provides doGet(), doTrace(), doOptions(), doPost(), doPut(), doDelete(), and other methods corresponding to HTTP protocol verbs. Since doGet, doTrace, and doOptions are all valid HttpServlet methods, 'All the Above' is the correct answer.
-
Servlets are built on JSP semantics and all servlets are compiled to JSP pages for runtime usage.
-
JSPs are built on servlet semantics and all JSPs are compiled to servlets for runtime usage.
-
JSP and servlets are unrelated technologies.
-
None of the Above
B
Correct answer
Explanation
JSP (JavaServer Pages) is built on servlet technology. During deployment, JSP pages are compiled into servlets by the container. Servlets are the underlying technology, not the other way around. JSP provides a template-based approach for generating dynamic content, but ultimately executes as servlets.
-
GenericServlet
-
HttpServlet
-
Both (A) and (B)
-
None of the Above
C
Correct answer
Explanation
In Java Servlet API, both GenericServlet (a protocol-independent servlet) and HttpServlet (a servlet specifically tailored for HTTP requests) are types of servlets. Therefore, both are valid servlet implementations, making the option "Both (A) and (B)" correct.
-
JSP Page
-
Java bean
-
Servlet
-
Session manager
A
Correct answer
Explanation
In Page-Centric architecture, the JSP page itself is the initial contact point for handling web requests. Unlike servlet-centric architectures where a servlet receives and processes requests first, page-centric designs route requests directly to JSP pages which may then delegate to beans or other components as needed.
-
doGet() or doPost() method
-
getServletInfo() method
-
All of the above
-
none of the above
A
Correct answer
Explanation
To process form submissions in a servlet, you subclass HttpServlet and override the doGet() or doPost() methods, depending on the HTTP request method used. The service() method automatically dispatches requests to these methods, so developers rarely need to override service() directly.
-
service() method
-
init() method
-
constructor for HttpServlet()
-
None of the Above
B
Correct answer
Explanation
The init() method is the designated place for servlet initialization code in the Servlet API lifecycle. It's called once when the servlet is first loaded. The service() method handles each request. The constructor is not the standard initialization point for servlets - init() guarantees the ServletConfig is available.
-
ServletContext
-
Servlet mapping
-
Lifecycle
-
None of the Above
B
Correct answer
Explanation
Servlet mapping is the association between a URL pattern and a servlet, defined in web.xml (or annotations). It tells the container which servlet should handle requests matching specific URL patterns. ServletContext is shared data across servlets. Lifecycle refers to servlet initialization/destruction. The mapping mechanism is essential for routing requests to correct servlets.
-
Servlet Interface
-
servlet mapping
-
Servlet Container
-
None of the Above
A
Correct answer
Explanation
All Servlets must implement the javax.servlet.Servlet interface, which defines the lifecycle methods (init, service, destroy) that the servlet container calls. Servlet mapping is a configuration concept, and Servlet Container is the runtime environment, not an interface to implement.