answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Set and get session attributes syntax in servlets and java script?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Information Science

What is semi join in SQL?

A semi-join returns rows from one table that would join with another table without performing a complete join. It doesn't have explicit syntax. Eg : semi join to evaluate an exists sub query select * from Customers C where exists ( select * from Sales S where S.Cust_Id = C.Cust_Id ) Cust_Id Cust_Name ----------- ---------- 2 John Doe 3 Jane Doe


Where can one find more information regarding XSL online?

There are multiple online resources where you can find more information regarding XSL. Some popular options include the World Wide Web Consortium (W3C) website, which provides the official XSL specifications and documentation, as well as tutorial websites like W3Schools or Tutorials Point, which offer beginner-friendly explanations and examples of XSL concepts and syntax. Additionally, online forums and communities such as Stack Overflow can be valuable sources for specific questions and discussions related to XSL.


What is the main difference between informational listening and critical listening?

Critical thinking uses rational reason, whereas in empathic listening tunes in to the feelings and emotions. Critical thinking involves determining the meaning and significance of what is observed or expressed, or, concerning a given inference or argument, determining whether there is adequate justification to accept the conclusion as true. Critical listening is listening in order to evaluate and judge, forming opinion about what is being said. Judgment includes assessing strengths and weaknesses, agreement and approval. This form of listening requires significant real-time cognitive effort as the listener analyzes what is being said, relating it to existing knowledge and rules, whilst simultaneously listening to the ongoing words from the speaker. Informational listening, the next step beyond discriminating between different sound and sights is to make sense of them. To comprehend the meaning requires first having a lexicon of words at our fingertips and also all rules of grammar and syntax by which we can understand what others are saying. The same is true, of course, for the visual components of communication, and an understanding of body language helps us understand what the other person is really meaning. In communication, some words are more important and some less so, and comprehension often benefits from extraction of key facts and items from a long spiel. Comprehension listening is also known as content listening, informative listening and full listening. One difference is the comprehensive or informational listening could be done before the critical listening.


Related questions

Syntax when using image tag to an HTML document?

The basic syntax is:Additional optional attributes include height, width, and border.


Where does the name syntax error come from?

syntax means synthesis that attributes comma,dash,slash and every keyword..however the deepest answer for evaluating this question is synthesis error.


Php Source code for validation?

If you wish to check the syntax of your source code, you need to run the code through the PHP CLI with the -l option. There are also some online resources to validate the syntax. This will check only the syntax of your file. This will not however detect runtime errors or logic errors. You must absolutely run the script for the best possible code validation.


What does HTML contain?

By contain I assume you mean the Syntax (Words), it is made up of tags such as and closing tags such as , also attributes such as to learn more about this visit http://w3schools.com/


Software for opening DXL ext files?

.dxl files are script files used for customising Telelogic DOORS. they can be edited through notepad or any other text editor. It is suggested though that using a syntax editor such as Crimson Edit or Xemacs with a DXL syntax file applied is better, then you can get syntax highlighting for key words, etc which makes debugging much simpler


What should I do when scope not digest in angular java script?

Apply $scope.$apply(); It's better to have apply in timeout syntax as below : SetTimeout(function() {$scope.$apply();},10);


What is Syntax Variation?

A syntax variation is a group of things that is syntax


How do you prevent syntax in programming?

Not possible; syntax cannot be avoided. (Syntax errors can be though.)


Are HTML tags and syntax the same?

No. Syntax is/are the rules of the language, tags are part of the syntax.


Is database design language a programming language?

No, it doesn't comprise any binary or computer language syntax. It simply uses schematic to graphic representation of tables structures and attributes as a mechanism to ease to the design process.


How syntax affect setting?

Syntax is essential to any form of language. Without syntax, there is no setting, there is no way to explain it and no language. Language and setting are both comprised with syntax.


How does syntax affect setting?

Syntax is essential to any form of language. Without syntax, there is no setting, there is no way to explain it and no language. Language and setting are both comprised with syntax.