answersLogoWhite

0


Best Answer

The session variables can be accessed in a jsp page from the request object.

Note: Accessing session contents in JSP is not a good design practice

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you set the session variables in jsp?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Basic Math

Which method invalidate session of a jsp page?

session.invalidate()


How do you reset session variables?

<?php // start session session_start(); // Assign value to session $user = $_SESSION['variable_name']; // variable_name = value to store in session // To reset session variable use below method unset($user); // If you want to destroy all session variables use below method session_destroy(); // destroys all session variables ?>


How do you maintain a session in a PHP quiz script?

All you have to do to maintain a session is start it before you call any variables. Once you've started the session, you can store variables for use in later scripts. Beware though, once the user closes the browser, the sessions' over. I'd use the following SCRIPT 1: <?php // Start session session_start(); // Set some variables (this simulates form input) $_SESSION['answers']['Q1'] = 18; $_SESSION['answers']['Q2'] = 36; $_SESSION['answers']['Q4'] = "Fred"; ?> ============================= Hope that helps...


How do you transfer values from javascript to JSP?

You can set the value in the hidden form fields using javascript and access the form fields in JSP


What is JSP Implicit objects?

In any JSP Page, there are a bunch of implicit objects that are available for the programmer to use. It contains a variety of information that can be used to display stuff on the page. The following JSP Implicit Objects are available for a programmer: • request • response • out • session • config • application • page • pageContext

Related questions

Can I prevent the creation of a session in a JSP page?

Yes you can. Use the below line in your JSP page to accomplish it. <%@ page session="false" %>


What method do you override to initialize instance variables in a JSP declaration?

jsp init()


Which method invalidate session of a jsp page?

session.invalidate()


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.


How can you display all the session variables in an HTML page?

HTML is a static language and hence access to Sessions is not available in HTML pages. Sessions are accessible only for J2EE systems that use Servlets, JSP etc.


How do you reset session variables?

<?php // start session session_start(); // Assign value to session $user = $_SESSION['variable_name']; // variable_name = value to store in session // To reset session variable use below method unset($user); // If you want to destroy all session variables use below method session_destroy(); // destroys all session variables ?>


What variables are maintained while the browser is opened?

Session Variables


Set and get session attributes syntax in servlets and java script?

Setting and getting session attributes is fairly easy. It is the same in both Servlets and JSPs with one exception. In a JSP, you already have access to the session object, and you do not have to declare it. In a Servlet, you must get the session like this: javax.servlet.http.HttpSession session = request.getSession(); Once you have done that, you can set a session object like this: session.setAttribute("name","value"); To retrieve the value, do this: String foo = (String) session.getAttribute("name"); A couple of things to keep in mind: * The second parameter in the setAttribute method is an Object, not a String. When you retrieve the value, you have to cast it. In the example above, I am casting it to a String. * If you try to perform a getAttribute on a session attribute that does not exist, or was not set, it will return a null. * Session attributes are not available using JavaScript. You can not set or get an attribute in JavaScript. * You do NOT need to do the 'session = request.getSession() in a JSP. It is only necessary in a Servlet.


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.


HOW CAN WE REGISTER THE VARIABLES INTO A SESSION?

$_SESSION['name'] = "RAGHAV";


How do you maintain a session in a PHP quiz script?

All you have to do to maintain a session is start it before you call any variables. Once you've started the session, you can store variables for use in later scripts. Beware though, once the user closes the browser, the sessions' over. I'd use the following SCRIPT 1: <?php // Start session session_start(); // Set some variables (this simulates form input) $_SESSION['answers']['Q1'] = 18; $_SESSION['answers']['Q2'] = 36; $_SESSION['answers']['Q4'] = "Fred"; ?> ============================= Hope that helps...


How do you transfer values from javascript to JSP?

You can set the value in the hidden form fields using javascript and access the form fields in JSP