answersLogoWhite

0

What does servlet session API means?

Updated: 9/18/2023
User Avatar

Wiki User

13y ago

Best Answer

The Servlet Session API refers to the documentation on the list of methods available in the HttpSession class that is used for Session Management

The HttpSession object is very powerful and has many features. Before we dig deep into the world of Sessions, let us take a look at the important methods they have so that we can use them effectively.

• getAttribute(java.lang.String name) - Returns an Object associated with that name that was stored in the session object.

• getAttributeNames() - Returns an Enumeration object that lists the names of the objects stored in the session object.

• getCreationTime() - Returns a long containing the date stamp of creation.

• getId() - Returns the id of the session as a String representing the unique identifier assigned to this session.

• getLastAccessedTime() - Returns a long containing the date stamp of the last time the session was accessed.

• getMaxInactiveInterval() - Returns an integer representing the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.

• invalidate() - This destroys a session. It can't be referenced after this method has been called.

• isNew() - This tells you whether the client knows about the session. In other words, the has session been created by the server, but the client hasn't acknowledged receiving the session ID yet.

• removeAttribute(java.lang.String name) - This removes an attribute. It deletes it from the session object.

• setAttribute(java.lang.String name, java.lang.Object value) - You use this method to add objects to a session.

• setMaxInactiveInterval(int interval) - Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.

• getValue(java.lang.String name) - Returns an Object associated with that name that was stored in the session object. As of Version 2.2, this method is replaced by getAttribute(). The getAttribute() method will be on the exam, not this one, but it is here for completeness.

• getValueNames() - Returns a String array with a list of names associated with the objects added to a given session. As of Version 2.2, this method is replaced by getAttributeNames(). The getAttributeNames() method will be on the exam, not this one, but it is here for completeness.

• putValue(java.lang.String name, java.lang.Object value) - You use this method to add objects to a session. This has been deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object). The setAttribute() method will be on the exam, not this one, but it is here for completeness.

• removeValue(java.lang.String name) - This removes a value, but retains an attribute name in the session. The name is valid but the object is null. This has been deprecated. As of Version 2.2, this method is replaced by removeAttribute(). The removeAttribute() method will be on the exam, not this one, but it is here for completeness.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What does servlet session API means?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Basic Math

What is servlet and why it is used?

servlet is a small program which run on serverside,and it can not be downloaded at client side. java servlets dynamically extends the functionalities of a web server. main use is: session tracking: no of users (unique) visited u'r website. in order to use cookies..


What is servlet mapping?

A Servlet Mapping is a directive in the web.xml that tells the Servlet Container which class to use when a particular Servlet is called. A Servlet is a class within your Java Web Application. Let's say you have a servlet called MyServlet in the com.example.servlet package. You would need to have a Servlet Mapping pointing the path "/MyServlet" to the "com.example.servlet.MyServlet" class. Without the servlet mapping, you would not be able to invoke your servlet because the Servlet container would not know where it is. JSPs are different - they do not need mappings like this. JSPs exist within the WebRoot of the application, so they are always available. Servlets exist in the WEB-INF\Classes directory once your application is deployed.


What are the servlet config methods?

Methods in the Servlet ContextApart from setting and getting custom attributes used for our application, the context also contains various methods that we can use to retrieve specific information about the application and other aspects. They are:• getAttributeNames() - Returns an Enumeration object containing the attribute names available within this servlet context.• getContext(String uripath) - Returns a ServletContext object that corresponds to a specified URL on the server.• getInitParameter(String name) - Returns a string containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.• getInitParameterNames() - Returns the names of the context's initialization parameters as an Enumeration of string objects, or an empty Enumeration if the context has no initialization parameters.• getMajorVersion() - Returns the major version as an int of the Java Servlet API that this Servlet Container supports.• getMimeType(java.lang.String file) - Returns the MIME type as a string of the specified file, or null if the MIME type is not known.• getMinorVersion() - Returns the minor version as an int of the Servlet API that this Servlet Container supports.• getNamedDispatcher(String name) Returns a RequestDispatcher object that acts as a wrapper for the named servlet.• getRealPath(String path) - Returns a string containing the real path for a given virtual path.• getRequestDispatcher(String path) Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.• getResource(String path) - Returns a URL to the resource that is mapped to a specified path.• getResourceAsStream(String path) - Returns the resource located at the named path as an InputStream object.• getServerInfo() Returns the name and version as a String of the Servlet Container on which the servlet is running.


Can you use constructor in servlet?

Yes you can but it is not required. A Servlet is nothing but another .java file and all rules that are applicable to standard Java classes are applicable to them. Note: Even if you write a constructor in a servlet, it will not get executed.


What is the difference between JSP and Servlets?

A JSP is typically oriented more towards displaying information, and a servlet is more oriented towards processing information. For example, a JSP might display a report, while a servlet would process a user submitted form. These uses are not exclusive, but they are optimized more for performing tasks in this manner. It is much easier to incorporate HTML coding into a JSP than a Servlet. It is also easier to write more complex Java code in a servlet.AnswerJSP has Implicit objects and Servlets do not. AnswerJSP and Servlet both define the server end functionality to provide dynamic outputs ,As we know our HTML is only the client end technology version which runs on client browser. JSP and Servlet differ each other in terms of represntation and execution cycle. Servlet are full functional java codes that define the output like write to stream files in protocol defined ways, JSP on the other hand is Role Sepated format to do so where a ordinary web designer designes how will be the presentation of the data and Programmer defines the functinality to provide the underlying things represented in conditional and non conditinal ways , But here is the magic of JSp that merges the both HTML represntation mixed with JAVA scriptlets. Look at http://www.jsptube.com/jsp-tutorials/jsp-introduction.html, it explains how does JSP differs from servlet.

Related questions

Session tracking in servlet?

Each web application contains a Session that can contain data that can be commonly made available to all the parts of the web application. The Session can be accessed from both the JSP and the Servlet. Ex: The servlet contains references to the HttpRequest object. So to access the session you can do so as below: HttpSession session = request.getSession();


How is statelessness of http overcome to run e-commerce applications on web?

it can be overcome by implementing session tracking & management in the running program on the server side. There are four solutions 1. Cookies, 2. Hidden from field, 3. URL rewriting and 4.Servlet Session API


How many scope are there in servlet?

The two scopes are: Request & Session


What servlet API used for database connection?

The Servlet 2.3 API consists of two packages: javax.servlet and javax.servlet.http. The base functionality is defined in the javax.servlet package whose classes and interfaces outline a generic, protocol-independent implementation. This means you can use it for non-Web applications, too. The javax.servlet.http interface defines classes and interfaces that are specific to the Hypertext Transfer Protocol (HTTP).


What is Servlet API used for connecting database?

The Servlet API is not specifically used for connecting to databases. Instead, servlets typically interact with databases through JDBC (Java Database Connectivity), which is a standard Java API for database access. Servlets can use JDBC to establish connections, execute SQL queries, and retrieve results from a database.


What is java servlet chaining?

Servlet Chaining means the output of one servlet act as a input to another servlet. Servlet Aliasing allows us to invoke more than one servlet in sequence when the URL is opened with a common servlet alias. The output from first Servlet is sent as input to other Servlet and so on. The Output from the last Servlet is sent back to the browser. The entire process is called Servlet Chaining.


Why you use session in hibernate?

Hi its me Riaz Molwani : Session is a bessically class of hibernate API which provide the interface between the presistent data objects store and the application . .


What is session in jsp?

Session in the JSP and Servlet context refers to an instance of the HttpSession object that contains all the information about the current user session with the web application. This can be used as a cache or temporary storage area to store values that might be required across the application.


What is servlet and why it is used?

servlet is a small program which run on serverside,and it can not be downloaded at client side. java servlets dynamically extends the functionalities of a web server. main use is: session tracking: no of users (unique) visited u'r website. in order to use cookies..


What are types of servlet?

Http servlet and Generic servlet


What is difference between single threaded servlet and multi threaded servlet?

The single thread model means that your servlet would not be multi-threaded. If there are two concurrent requests to your servlet then 2 instances of your servlet will be created to process these 2 requests. You can implement the single thread model by implementing the SingleThreadModel interface in your class. This is just a marker interface and does not have any methods. The multi threaded model means that your servlet would be multi-threaded and only one instance would exist. Multiple concurrent requests would be served by the same instance but in different threads. You can implement the multi threaded model by not implementing the SingleThreadModel interface in your servlet class.


How do you dynamically identify the jsp in servlet?

You can dynamically identify the JSP file in a servlet by using the request URL or request parameters to determine which JSP to forward the request to. You can also store necessary information in session attributes or external configurations to help determine the appropriate JSP to display. Finally, you can use a servlet mapping or URL pattern to route requests to different JSP files based on the URL.