- 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 9326 Articles for Object Oriented Programming
1K+ Views
SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting.Let us modify the above example as follows −Example Live Demo Display Current Date & Time Display Current Date & Time Compile the above servlet once again and then call this servlet using the URL http://localhost:8080/CurrentDate. You will receive the following result −OutputDisplay Current Date & Time Mon 2010.06.21 at 10:06:44 PM GMT+04:00
12K+ Views
With JSP program, it is very easy to get the current date and the time. You can use a simple Date object with the toString() method to print the current date and the time as follows −Example Live Demo Display Current Date & Time Display Current Date & Time Let us now keep the code in CurrentDate.jsp and then call this JSP using the URL http://localhost:8080/CurrentDate.jsp. You will receive the following result −OutputDisplay ... Read More
389 Views
A JSP can be used with an HTML form tag to allow users to upload files to the server. An uploaded file can be a text file or a binary or an image file or just any document.Creating a File Upload FormLet us now understand how to create a file upload form. The following HTML code creates an uploader form. Following are the important points to be noted down −The form method attribute should be set to POST method and the GET method cannot be used.The form enctype attribute should be set to multipart/form-data.The form action attribute should be set ... Read More
396 Views
A JSP can be used with an HTML form tag to allow users to upload files to the server. An uploaded file can be a text file or a binary or an image file or just any document.Creating a File Upload FormLet us now understand how to create a file upload form. The following HTML code creates an uploader form. Following are the important points to be noted down −The form method attribute should be set to the POST method and the GET method cannot be used.The form enctype attribute should be set to multipart/form-data.The form action attribute should be ... Read More
859 Views
When you are done with a user's session data, you have several options −Remove a particular attribute − You can call the public void removeAttribute(String name) method to delete the value associated with the particular key.Delete the whole session − You can call the public void to invalidate() method to discard an entire session.Setting Session timeout − You can call the public void setMaxInactiveInterval(int interval) method to set the timeout for a session individually.Log the user out − The servers that support servlets 2.4, you can call log out to log the client out of the Web server and invalidate ... Read More
432 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
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
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
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
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