- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 177 Articles for JSP
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
438 Views
This example describes how to use the HttpSession object to find out the creation time and the last-accessed time for a session. We would associate a new session with the request if one does not already exist.Example Live Demo Session Tracking Session Tracking Session info Value ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
3K+ Views
JSP makes use of the servlet provided HttpSession Interface. This interface provides a way to identify a user across.a one-page request orvisit to a website orstore information about that userBy default, JSPs have session tracking enabled and a new HttpSession object is instantiated for each new client automatically. Disabling session tracking requires explicitly turning it off by setting the page directive session attribute to false as follows −The JSP engine exposes the HttpSession object to the JSP author through the implicit session object. Since session object is already provided to the JSP programmer, the programmer can immediately begin storing and ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
4K+ Views
HTTP is a "stateless" protocol which means each time a client retrieves a Webpage, the client opens a separate connection to the Web server and the server automatically does not keep any record of previous client request.Maintaining Session Between Web Client And ServerLet us now discuss a few options to maintain the session between the Web Client and the Web Server −CookiesA webserver can assign a unique session ID as a cookie to each web client and for subsequent requests from the client they can be recognized using the received cookie.This may not be an effective way as the browser ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
To delete cookies is very simple. If you want to delete a cookie, then you simply need to follow these three steps −Read an already existing cookie and store it in Cookie object.Set cookie age as zero using the setMaxAge() method to delete an existing cookie.Add this cookie back into the response header.Following example will show you how to delete an existing cookie named "first_name" and when you run main.jsp JSP next time, it will return null value for first_name.Example Live Demo Reading Cookies ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
To read cookies, you need to create an array of javax.servlet.http.Cookie objects by calling the getCookies( ) method of HttpServletRequest. Then cycle through the array, and use getName() and getValue() methods to access each cookie and associated value.Let us now read cookies that were set in the previous example −Example Live Demo Reading Cookies Reading Cookies Let us now put the above code in main.jsp file and try to access it. If you set ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
Setting cookies with JSP involves three steps −Step 1: Creating a Cookie objectYou call the Cookie constructor with a cookie name and a cookie value, both of which are strings.Cookie cookie = new Cookie("key", "value");Keep in mind, neither the name nor the value should contain white space or any of the following characters −[ ] ( ) = , " / ? @ : ;Step 2: Setting the maximum ageYou use setMaxAge to specify how long (in seconds) the cookie should be valid. The following code will set up a cookie for 24 hours.cookie.setMaxAge(60*60*24);Step 3: Sending the Cookie into the ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
180 Views
Cookies are usually set in an HTTP header (although JavaScript can also set a cookie directly on a browser). A JSP that sets a cookie might send headers that look something like this −HTTP/1.1 200 OK Date: Fri, 04 Feb 2000 21:03:38 GMT Server: Apache/1.3.9 (UNIX) PHP/4.0b3 Set-Cookie: name = xyz; expires = Friday, 04-Feb-07 22:03:38 GMT; path = /; domain = tutorialspoint.com Connection: close Content-Type: text/htmlAs you can see, the Set-Cookie header contains a name value pair, a GMT date, a path and a domain. The name and value will be URL encoded. The expires field is an instruction ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
238 Views
Cookies are text files stored on the client computer and they are kept for various information tracking purposes. JSP transparently supports HTTP cookies using underlying servlet technology.There are three steps involved in identifying and returning users -Server script sends a set of cookies to the browser. For example, name, age, or identification number, etc.Browser stores this information on the local machine for future use.When the next time the browser sends any request to the web server then it sends those cookies information to the server and server uses that information to identify the user or may be for some other ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
647 Views
Your web application may define several different filters with a specific purpose. Consider, you define two filters AuthenFilter and LogFilter. Rest of the process will remain as explained above except you need to create a different mapping as mentioned below − LogFilter LogFilter test-param Initialization Paramter AuthenFilter AuthenFilter test-param Initialization Paramter LogFilter /* AuthenFilter /* Filters Application OrderThe order of filter-mapping elements ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
495 Views
Following example shows how to print the client's IP address and the current date time, each time it would access any JSP file. This example will give you a basic understanding of the JSP Filter, but you can write more sophisticated filter applications using the same concept −// Import required java libraries import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; // Implements Filter class public class LogFilter implements Filter { public void init(FilterConfig config) throws ServletException { // Get init parameter String testParam = config.getInitParameter("test-param"); //Print the init parameter ... Read More