0% found this document useful (0 votes)
63 views3 pages

Java Servlet Session Tracking Guide

The document provides instructions for a lecture assignment on session tracking and database programming in Servlets. It includes 6 questions asking students to: 1) define session tracking and its techniques, 2) provide example code for using hidden values for session tracking, 3) write code to set cookies in a browser, 4) write code to display stored cookies, 5) write code to pass parameters via URL rewriting, and 6) write code using the Servlet API to track sessions and welcome returning users. Students are asked to answer in their own words and not copy from other sources.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views3 pages

Java Servlet Session Tracking Guide

The document provides instructions for a lecture assignment on session tracking and database programming in Servlets. It includes 6 questions asking students to: 1) define session tracking and its techniques, 2) provide example code for using hidden values for session tracking, 3) write code to set cookies in a browser, 4) write code to display stored cookies, 5) write code to pass parameters via URL rewriting, and 6) write code using the Servlet API to track sessions and welcome returning users. Students are asked to answer in their own words and not copy from other sources.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Lecture Assignment

Tutorial Week 5
Our readings (lecture notes and video lecture) this week discuss the Servlet (session tracking
and database programming in Servlet). Write the answers for all questions in the table
according to your understanding. PLEASE USE YOUR OWN WORDS. DO NOT COPY FROM
THE WEB.

Questions Answers
1. What is session tracking? What are the three techniques for session tracking is series of interactions to
session tracking? track data among requests over a period

techniques:
- Using hidden values
- Using cookies
- Using URL rewriting

2. How do you use hidden values in HTML form for session public class FirstServlet extends
tracking? Write example code for session tracking using HttpServlet
hidden values based on the following figure. {
public void doPost(HttpServletRequest
request, HttpServletResponse response)
{
try
{

[Link]("text/html");
PrinterWriter out =
[Link]();

String
nm=[Link]("name");
String em =
[Link]("emailID");

MMR2020@FSKM
Lecture Assignment

[Link]("Welcome"+n);

//creating form that have insible


textfield
[Link]("<form action = 'servlet2'>");
[Link]("Enter Country <input type =
'text' name = 'country'>");
[Link]("<input type = 'hidden'name
= 'name'value = '"+nm+"'>");
[Link]("<input type='hidden'
name='email' values!"+egsis°);
[Link]("<input type=' submit'
values'subait's");
[Link]("</form");
[Link]();
}
catch (Exception e)
([Link](e);)
}
}
3. Write a servlet that stores the following cookies in a browser Cookie(“color”,”red”);
and set their max age for two days: Cookie cookie2 = new
Cookie 1: name is “color” and value is red. Cookie(“radius”,”5.5”);
Cookie 2: name is “radius” and value is 5.5. Cookie cookie3 = new
Cookie 3: name is “count” and value is 2. Cookie(“count”,”2”);
[Link](cookie1);
[Link](172800);
4. Write a servlet that display all the cookies on the client. The Cookie c[]=[Link]();
client types the URL of the servlet from the browser to display for(int i=0;i<[Link];i++){
all the cookies stored on the browser. [Link]("Name: "+c[i].getName()+" &
Value: "+c[i].getValue());
}
5. Write a servlet [Link] that retrieve values from a url [Link]("text/html");

MMR2020@FSKM
Lecture Assignment

html form and send parameter name and studentID using PrintWriter out =
URL rewriting technique to another servlet. Use [Link]();
getParameter() method to obtain a parameter value. String
n=[Link]("username
");
[Link]("Welcome "+n+" ");
//appending the username in
the query string
[Link]("<a
href='servlet2?uname="+n+"&StudId=”+s+

'>visit</a>");
[Link]();
6. Create a servlet [Link] and use session HttpSession
tracking using the Servlet API to keep track the session and session=[Link]();
display “Welcome to CSC584 class” to first-time visitors [Link]("uname",N);
(within a browsing session) and “Welcome Back” to repeat if([Link]()) {
visitors. If you did this same task earlier with the Cookie API, [Link]("Welcome to
was this servlet harder or easier than the equivalent version CSC584 class "+N);
using cookies explicitly? count = 0;
}
else {
[Link]("Welcome Back "+N);
count++;
}
if(count >=10) {
[Link]();
}

MMR2020@FSKM

Common questions

Powered by AI

Session tracking is crucial in web applications for maintaining the continuity and state of user interactions across multiple HTTP requests, which are inherently stateless. It allows applications to remember user-specific data, such as login status or shopping cart contents, across different pages or visits. Without session tracking, each request would be independent, making it impossible to store user preferences or progress effectively .

Implementing a session timeout policy using the Servlet API enhances security by automatically ending sessions after a period of inactivity, reducing the window for session hijacking attacks. While this improves security, it can negatively affect user experience by requiring users to re-authenticate after timeout, which may disrupt their activity. Balancing between security and user experience is crucial, where a timeout period is chosen to provide security while allowing reasonable user interaction duration .

Session tracking can affect a web application's scalability and performance by increasing the server's overhead to store and manage state data for multiple users. Techniques like URL rewriting and hidden fields rely on server resources for each request, while cookies offload data storage to the client, slightly improving scalability. However, extensive use of session data can lead to memory bloat and slower response times as more state data is handled per user session. Proper session management, such as efficient session expiration policies and load balancing strategies, can mitigate these issues and support better scalability .

The HttpSession API provides a more secure and server-side approach to session management compared to cookies. With HttpSession, session data is stored on the server, minimizing the risk of client-side tampering . It simplifies session handling, as it abstracts complex tasks like session ID management and expiry handling, which are manually handled when using cookies. However, cookies might still be needed to track session IDs when the HttpSession API is used, but the overall implementation using HttpSession tends to be more straightforward for developers .

Cookies are stored on the client's browser, allowing persistence across sessions and easy user-specific state management, but can be disabled by users for privacy reasons. Hidden fields store state data in forms between page submissions, keeping data on the server side but requiring form submissions to transfer state, which can be cumbersome for some applications . URL rewriting appends session data to the URL, which works even when cookies are disabled, but exposes session data in the address bar, potentially posing security risks .

Designing a servlet-based application that relies on cookies requires careful consideration of user privacy and data security. Developers must ensure cookies are secured via HTTPS, limiting access to only trustworthy domains and defining appropriate scopes and expiration policies to protect data integrity. It's also important to respect user preferences by providing clear controls over cookie usage and ensuring compliance with privacy regulations like the GDPR. Additionally, cookies should be efficiently managed to minimize storage implications and potential for misuse .

Hidden fields in multi-step form submission can become complex due to the necessity of carrying forward all data collected in previous steps. Each step must include all prior hidden values plus any new data collected, increasing the complexity of the form management and increasing the risk of errors if values are not correctly managed or transmitted. Moreover, if any step fails or is refreshed, it may lead to data loss without server-side backup mechanisms .

URL rewriting in session tracking involves appending session-specific data to the URLs that users interact with. This method is particularly useful when cookies are not available or are disabled by users. However, URL rewriting has security implications since the session data becomes visible in the URLs, making it susceptible to being copied or tampered with. This can lead to session hijacking if sensitive information is stored in the URL. Proper encryption and validation measures should be employed to mitigate these risks .

Session tracking supports personalization by allowing web applications to remember user preferences, activities, and login details to provide a tailored user experience. However, it raises privacy concerns as it involves collecting and storing user data, which can be personally identifiable. Inappropriate handling or unauthorized access to session data can lead to breaches of privacy. Thus, implementing robust data protection practices, consent mechanisms, and transparency in data storage policies are necessary to mitigate these concerns .

URL rewriting is preferred over cookies when there is a need to ensure session data is transmitted across devices that might not support cookies due to restrictions or deliberate user settings. It's also useful when targeting environments known for stringent privacy policies disabling cookies. However, it should be used cautiously due to security implications, such as data exposure, suggesting a need to employ additional steps to secure the transmitted session data .

You might also like