A developer needs to implement complex business logic with minimal HTML. Should they choose Servlet or JSP?
- Both
- JSP
- None of the above
- Servlet
When implementing complex business logic with minimal HTML, Servlets are more suitable as they provide better control over the business logic, separating it from the presentation layer. JSP is better for the view layer and is commonly used for creating dynamic web pages with embedded Java code.
In a servlet, to get an array of all the values of a multi-valued parameter, use the __________ method.
- getArrayValues()
- getMultiValuedParameter()
- getParameterValues()
- retrieveParameterArray()
The getParameterValues() method in a servlet is used to get an array of all the values of a multi-valued parameter.
When handling file uploads in a servlet, the __________ utility class from Apache Commons FileUpload can be used.
- FileParser
- FileReader
- FileUpload
- FileWriter
When handling file uploads in a servlet, the FileUpload utility class from Apache Commons FileUpload is commonly used for parsing and processing multipart/form-data requests, including file uploads.
What object is primarily used to read form data in a servlet?
- FormReader
- HttpRequest
- HttpServletRequest
- ServletRequest
The HttpServletRequest object is primarily used to read form data in a servlet.
Which technology is primarily used for writing business logic in a web application?
- CSS
- HTML
- JSP
- Servlets
Servlets are primarily used for writing business logic in a web application.
To delete a cookie, the servlet should set its _________ to a past date.
- creation time
- domain
- expiration date
- path
To delete a cookie, the servlet should set its expiration date to a past date, making it immediately invalid.
ServletConfig's getServletName() method returns the __________ of the servlet.
- ID
- alias
- handle
- name
ServletConfig's getServletName() method returns the name of the servlet.
The __________ method of HttpServletResponse causes the browser to request a new URL.
- forward()
- include()
- refresh()
- sendRedirect()
The sendRedirect() method of HttpServletResponse causes the browser to request a new URL.
To set the character encoding for the response body, use the __________ method of HttpServletResponse.
- setCharacterEncoding()
- setContentType()
- setEncoding()
- setResponseEncoding()
The setCharacterEncoding() method of HttpServletResponse is used to set the character encoding for the response body.
The method ___________ is used to read a single initialization parameter in the servlet.
- fetchParameter()
- getInitParam()
- getInitParameter()
- readInitParameter()
The method getInitParameter() is used to read a single initialization parameter in the servlet.
To handle JSON data in a POST request, a servlet may need to parse the request body using a _________.
- HttpServletRequest
- HttpServletResponse
- JsonObject
- JsonReader
In a POST request, to handle JSON data, a servlet may need to parse the request body using a JsonObject.
In servlets, thread-safety issues are often handled in the __________ method.
- destroy()
- doPost()
- init()
- service()
In servlets, thread-safety issues are often handled in the init() method.