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
-
LoginException
-
EnterpriseSecurityException
-
SecurityException
-
IntrusionException
B
Correct answer
Explanation
The login method throws EnterpriseSecurityException, which is a custom exception specific to the security framework being used. Standard Java exceptions like LoginException, SecurityException, or IntrusionException are not the correct custom exception for this API.
-
void setNoCacheHeaders(javax.servlet.http.HttpServletResponse response)
-
void setNoCacheHeaders(javax.servlet.http.HttpServletRequest request)
-
boolean setNoCacheHeader(javax.servlet.http.HttpServletResponse response)
-
void setNoCacheHeaders(javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException
A
Correct answer
Explanation
The setNoCacheHeaders() method takes an HttpServletResponse parameter and sets cache-control headers to prevent browsers and proxies from caching sensitive content. It doesn't need HttpServletRequest, doesn't return a boolean, and doesn't throw ServletException.
-
encryptHiddenField(java.lang.String value)
-
addCSRFToken(final java.lang.String href)
-
verifySecureComm(javax.servlet.http.HttpServletRequest request)
-
setSafeContentType(javax.servlet.http.HttpServletResponse response)
B
Correct answer
Explanation
The addCSRFToken() method is specifically designed to add CSRF protection tokens to links, which is the primary defense against cross-site request forgery attacks. The other methods serve different purposes: encryption, secure communication verification, and content type setting.
-
It checks if the http request is made on an SSL channel
-
It checks if the http method is a POST
-
Both of the above
-
None of the above
C
Correct answer
Explanation
The isSecureRequest method checks both SSL channel (HTTPS) and POST method. This dual check is important because sensitive data should be transmitted over SSL and state-changing operations should use POST, not GET.
-
Log Message which gets logged in the log file and not safe to display to users
-
User Message which is safe to display to users
-
Both of the above
-
None of the above
C
Correct answer
Explanation
EnterpriseSecurityException contains two types of messages - a log message for developers/sysadmins that may contain sensitive details, and a user message that is safe for end users. This separation prevents information leakage.
-
LoginException
-
EnterpriseSecurityException
-
SecurityException
-
IntrusionException
C
Correct answer
Explanation
The login() method handles user authentication and can fail for various reasons (invalid credentials, locked account, etc.). When authentication fails, it throws a SecurityException, which is the appropriate exception type for security-related failures in the API hierarchy.
-
void setNoCacheHeaders(javax.servlet.http.HttpServletResponse response)
-
void setNoCacheHeaders(javax.servlet.http.HttpServletRequest request)
-
boolean setNoCacheHeader(javax.servlet.http.HttpServletResponse response)
-
void setNoCacheHeaders(javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException
A
Correct answer
Explanation
The correct method signature uses HttpServletResponse as the parameter since caching headers are set on the response object. The method is void because it performs an action (setting headers) rather than returning a value. Option B incorrectly uses HttpServletRequest, and options C and D have incorrect return types or exception declarations.
-
encryptHiddenField(java.lang.String value)
-
addCSRFToken(final java.lang.String href)
-
verifySecureComm(javax.servlet.http.HttpServletRequest request)
-
setSafeContentType(javax.servlet.http.HttpServletResponse response)
B
Correct answer
Explanation
Cross Site Request Forgery (CSRF) prevention requires adding unpredictable tokens to requests that the server can verify. The addCSRFToken method is specifically designed for this purpose. Option A (encryption) and C (secure communication verification) address different security concerns, while D (content type) is about XSS prevention.
-
It checks if the http request is made on an SSL channel
-
It checks if the http method is a POST
-
Both of the above
-
None of the above
C
Correct answer
Explanation
The isSecureRequest method performs two critical security checks: verifying SSL usage (HTTPS) and ensuring the HTTP method is POST. POST over HTTPS provides confidentiality and is the standard for secure form submissions. Options A and B are each partially correct but incomplete.
-
Log Message which gets logged in the log file and not safe to display to users
-
User Message which is safe to display to users
-
Both of the above
-
None of the above
C
Correct answer
Explanation
EnterpriseSecurityException contains two types of messages: a log message for developers/system administrators and a user message safe for display. This separation prevents exposing sensitive technical details to end users while maintaining audit trails. Options A and B are each partially correct.
-
LoginException
-
EnterpriseSecurityException
-
SecurityException
-
IntrusionException
C
Correct answer
Explanation
The login method throws SecurityException when authentication fails or security violations occur during the login process. This is a standard exception type for security-related failures in Java security APIs, providing a clear indication of security-related issues.
-
void setNoCacheHeaders(javax.servlet.http.HttpServletResponse response)
-
void setNoCacheHeaders(javax.servlet.http.HttpServletRequest request)
-
boolean setNoCacheHeader(javax.servlet.http.HttpServletResponse response)
-
void setNoCacheHeaders(javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException
A
Correct answer
Explanation
Cache control headers must be set on the HttpServletResponse object, not the HttpServletRequest. The method returns void as it performs an action (setting headers) rather than returning a value. ServletException is not relevant to header operations, making option A the correct signature.
-
encryptHiddenField(java.lang.String value)
-
addCSRFToken(final java.lang.String href)
-
verifySecureComm(javax.servlet.http.HttpServletRequest request)
-
setSafeContentType(javax.servlet.http.HttpServletResponse response)
B
Correct answer
Explanation
Preventing Cross Site Request Forgery requires associating requests with a unique, unpredictable, and user-specific token. The addCSRFToken method appends this token to URLs, verifying that the request originated from the authenticated user rather than an external site.
-
It checks if the http request is made on an SSL channel
-
It checks if the http method is a POST
-
Both of the above
-
None of the above
C
Correct answer
Explanation
The isSecureRequest method performs comprehensive security validation by checking both if the request uses HTTPS (SSL/TLS encrypted channel) and if it's a POST method. This dual verification ensures sensitive operations only proceed over secure connections with appropriate HTTP methods.
-
Log Message which gets logged in the log file and not safe to display to users
-
User Message which is safe to display to users
-
Both of the above
-
None of the above
C
Correct answer
Explanation
EnterpriseSecurityException maintains two separate messages: a log message containing technical details for developers (written to log files, not shown to users) and a user message with sanitized, safe information appropriate for display to end users without exposing sensitive system details.