Skip to main content

Web Design and Development MCQs with Answers

Practice important Web Design and Development MCQs with answers and explanations.

Chapter: 31
Q481:
What does the getName() method of the Cookie class return?
A. The name of the cookie
B. The value of the cookie
C. The creation date of the cookie
D. The expiry date of the cookie
Correct Answer: A
Chapter: 31
Q482:
In the context of session tracking, what does URL rewriting involve?
A. Modifying cookie attributes
B. Appending session data to the URL
C. Encrypting session data
D. Deleting cookies from the server
Correct Answer: B
Chapter: 32
Q483:
Which Java class is used to handle HTTP requests and responses?
A. HttpServletRequest
B. HttpServletResponse
C. HttpServlet
D. HttpRequest
Correct Answer: C
Chapter: 32
Q484:
What is the purpose of response.addCookie(c) in Java servlets?
A. To delete a cookie from the client
B. To create and send a new cookie to the client
C. To read cookies sent by the client
D. To update cookie attributes
Correct Answer: B
Chapter: 32
Q485:
How can a servlet check if a specific cookie is present?
A. By inspecting the HTTP headers
B. By querying the database
C. By examining the URL
D. By analyzing the session ID
Correct Answer: A
Chapter: 32
Q486:
What is URL rewriting used for in session tracking?
A. Storing user credentials
B. Maintaining session information
C. Enhancing page load speed
D. Encrypting data
Correct Answer: B
Chapter: 32
Q487:
Which of the following is a disadvantage of URL rewriting?
A. Persistent state information
B. Limited to HTTP GET requests
C. Minimal computational cost
D. High security
Correct Answer: B
Chapter: 32
Q488:
In URL rewriting, how is session information typically passed?
A. In query strings
B. In cookies
C. In hidden form fields
D. In HTTP headers
Correct Answer: A
Chapter: 32
Q489:
What does the getSession(true) method return in the HttpSession API?
A. A new session if one does not exist
B. Null if no session exists
C. A session only if it is active
D. The current session without creating a new one
Correct Answer: A
Chapter: 32
Q490:
How do you store a value in a session object using the HttpSession API?
A. session.storeAttribute("key", value)
B. session.put("key", value)
C. session.setAttribute("key", value)
D. session.addAttribute("key", value)
Correct Answer: C
Chapter: 32
Q491:
What does the getAttribute("sessionid") method return if the attribute does not exist?
A. A default value
B. Null
C. An empty string
D. An error message
Correct Answer: B
Chapter: 32
Q492:
What is the primary use of hidden form fields in HTML forms?
A. To affect the layout of the form
B. To store session information
C. To add interactive elements
D. To provide form validation
Correct Answer: B
Chapter: 32
Q493:
Which method of HttpServletResponse is used to encode URLs for session tracking?
A. encodeURL
B. encodeSessionID
C. rewriteURL
D. encodeRedirectURL
Correct Answer: A
Chapter: 32
Q494:
What is the purpose of the invalidate() method in HttpSession?
A. To create a new session
B. To terminate the current session
C. To update session attributes
D. To retrieve session information
Correct Answer: B
Chapter: 32
Q495:
In the provided Java code, what is the purpose of makeUniqueString() method in URLRewriteServlet?
A. To generate a unique session ID
B. To create a new user session
C. To store session attributes
D. To encode URLs for session tracking
Correct Answer: A
Chapter: 32
Q496:
How does encodeRedirectURL() differ from encodeURL() in session management?
A. It is used for URLs in server redirects
B. It is used for URLs embedded in web pages
C. It encodes URLs for JavaScript usage
D. It handles URLs for AJAX requests
Correct Answer: A
Chapter: 32
Q497:
What does the getCreationTime() method of HttpSession return?
A. The time the session was last accessed
B. The time the session was created
C. The time the session was last modified
D. The time the session was terminated
Correct Answer: B
Chapter: 33
Q498:
In the provided ShowSessionServlet code, what happens when accessCount is null?
A. The session is terminated
B. A new access count is initialized
C. An error is thrown
D. The session is invalidated
Correct Answer: B
Chapter: 33
Q499:
What is the output if session.getId() is called in a servlet?
A. The unique session ID
B. The time of the last session access
C. The session's creation time
D. The number of accesses to the session
Correct Answer: A
Chapter: 33
Q500:
In ShoppingCartServlet, what happens when the book parameter equals "first"?
A. The book is added to the session as "second"
B. The book is removed from the session
C. The book is added to the session as "first"
D. The book is displayed in the HTML output
Correct Answer: C

Test Your Knowledge

Take a timed quiz on Web Design and Development

🚀 Start Quiz Now