The annotation _________ is used to configure the endpoint of a WebSocket server.
- @EndpointConfig
- @ServerEndpoint
- @WebSocketConfig
- @WebSocketEndpoint
The annotation @ServerEndpoint is used to configure the endpoint of a WebSocket server.
A servlet receives a POST request with JSON data. What are the steps to correctly parse and use this data?
- Use the doGet() method and manually parse the JSON data using a JSON library.
- Use the doGet() method and rely on the servlet container to automatically parse the JSON data.
- Use the doPost() method and manually parse the JSON data using a JSON library.
- Use the doPost() method and rely on the servlet container to automatically parse the JSON data.
When handling a POST request with JSON data, it is appropriate to use the doPost() method, and manual parsing is often necessary using a JSON library. The servlet container does not automatically parse JSON data.
The _________ interface in Java EE allows the server to react to WebSocket lifecycle events.
- Decoder
- Encoder
- Endpoint
- Session
The Endpoint interface in Java EE allows the server to react to WebSocket lifecycle events.
To handle binary data in a WebSocket, the _________ method is typically implemented.
- onBinaryMessage
- onClose
- onError
- onTextMessage
To handle binary data in a WebSocket, the onBinaryMessage method is typically implemented.
WebSocket connections are maintained even if the underlying _________ changes, like from HTTP to HTTPS.
- URI
- protocol
- security
- transport
WebSocket connections are maintained even if the underlying URI changes, like from HTTP to HTTPS.
What is a common practice to reduce the load on a servlet?
- Caching
- Database Connection Pooling
- Lazy Loading
- Multithreading
Database Connection Pooling is a common practice to reduce the load on a servlet by efficiently managing and reusing database connections, improving performance.
Which of the following is a recommended approach to handle database connections in servlets?
- Closing connections after each request
- Connection pooling
- Opening new connections for each request
- Using a singleton connection
Connection pooling is a recommended approach for handling database connections in servlets, as it optimizes resource usage and enhances performance.
Why is it important to close resources like database connections in servlets?
- All of the above
- To avoid memory leaks
- To conserve memory
- To improve performance
Closing resources like database connections is important to avoid memory leaks and ensure efficient memory usage in servlets.
How does using the PreparedStatement in servlets improve performance?
- PreparedStatements allow for batch processing.
- PreparedStatements are precompiled, reducing SQL parsing overhead.
- PreparedStatements are suitable for handling large datasets.
- PreparedStatements automatically manage database connections.
Using PreparedStatements in servlets improves performance as they are precompiled, reducing SQL parsing overhead, which leads to better execution speed.
How does the sendRedirect() method communicate the new URL to the client's browser?
- Via HTTP headers
- Via HTTP status code
- Via URL parameters
- Via server-side cookies
The sendRedirect() method communicates the new URL to the client's browser by sending an HTTP redirect response with the new URL in the HTTP headers.