Skip to main content

Important Web Design and Development Short Questions

Chapter: 30
Question 1:
Describe the role of setAttribute() and getAttribute() methods in HttpServletRequest.
Answer: setAttribute(String key, Object value) is used to store data in the request scope, making it available to other resources handling the same request. getAttribute(String key) retrieves the stored data by key from the request scope.
Chapter: 30
Question 2:
How does the forward method of RequestDispatcher differ from include method?
Answer: The forward method transfers control to another resource and the calling resource’s response is not used. The include method incorporates the output of another resource into the calling resource's response.
Chapter: 30
Question 3:
What does the getMethod() method of HttpServletRequest return?
Answer: The getMethod() method returns the HTTP method used for the request, which can be either "GET" or "POST".
Chapter: 30
Question 4:
How can response.setContentType() be used in a servlet?
Answer: response.setContentType(String type) sets the MIME type of the response content, such as "text/html" for HTML content, which informs the client browser how to interpret the data being sent.
Chapter: 30
Question 5:
Explain the importance of session tracking in web applications.
Answer: Session tracking maintains state across multiple requests from the same client, such as keeping track of user activities like shopping cart contents, as HTTP itself is stateless and does not retain information between requests.
Chapter: 30
Question 6:
What is the purpose of the sendRedirect() method in HttpServletResponse?
Answer: The sendRedirect(String location) method redirects the client to a different URL. It creates a new request to the specified URL and can be used to navigate to another servlet, JSP, or external page.
Chapter: 31
Question 7:
What is the primary purpose of session tracking in web applications?
Answer: Session tracking is used to maintain a conversational state between the client and server across multiple requests. It ensures that user interactions, such as items in a shopping cart, are preserved throughout the user's session.
Chapter: 31
Question 8:
What are cookies and how are they used in session tracking?
Answer: Cookies are small pieces of text stored on a client's hard disk by a web server. They are used to track user sessions by storing information like session IDs, which allows the server to identify and manage user sessions across multiple requests.
Chapter: 31
Question 9:
What are the main methods used for session tracking?
Answer: The main methods for session tracking include cookies, URL rewriting, and hidden fields. Each method offers different ways to maintain session state between the client and server.
Chapter: 31
Question 10:
How does the server handle cookies when a client requests a web page?
Answer: When a client requests a web page, the browser sends any relevant cookies associated with the server. The server then examines these cookies to identify the client and retrieve session information. If no cookies are present, the server may set new ones.