Given the code below:
4 phương ánCó giải thích
HttpSession session = request.getSession();
session.setAttribute("username", "HuyNM");Which of the following is incorrect?
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "The attribute is stored in the client browser's local storage". Dữ liệu đặt bằng setAttribute nằm trong đối tượng HttpSession do container giữ trong bộ nhớ của server; thứ duy nhất đi về phía trình duyệt là định danh phiên, thường là cookie JSESSIONID, nên không có mẩu dữ liệu nào tên username được ghi vào kho lưu trữ của trình duyệt. "The session must exist or be created automatically" là mệnh đề đúng, vì request.getSession() không tham số trả về phiên đang có hoặc tạo mới nếu chưa có, nhờ vậy dòng mã luôn có chỗ để ghi. Mệnh đề nói giá trị "can be retrieved later using the same session" cũng đúng, vì getAttribute với cùng tên trong cùng phiên sẽ lấy lại được đối tượng đã đặt. "The attribute will persist across multiple HTTP requests" đúng nốt, bởi phiên tồn tại xuyên nhiều yêu cầu cho tới khi hết thời gian chờ hoặc bị invalidate, đó chính là lý do người ta dùng phiên thay cho phạm vi request.
Cùng phần 6
How can Session Tracking be done?Có lời giảiCâu hỏiWhat is the most secure way to handle session invalidation during logout?Có lời giảiCâu hỏiAssuming that there is a link logout at the top of the profile.jsp, orderhistory.jsp.
<a href="logoutServlet">Logout</a>
When the client clicks the logout link, the following code in the logoutServlet runs:
HttpSession session = request.getSession();
//TODO
response.sendRedirect("login.jsp");
What is the best code to write in the TODO section to complete the logout function?Có lời giảiCâu hỏiCả 25 câu của chủ đề25 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây