how to maintain sessions in jsp?can you tellme the methods.
Answers were Sorted based on User's Feedback
Answer / manu
A small correction at **
using session oject in jsp.
first u set using following methods
String name="ravi";
session.setAttribute("user",name);
using retrive method
String sessionuser=session.getAttribute("user");**
out.println("welcome"+sessionuser);
u give this last 2 stmts in all jsp pages. it will
display as "Welcome ravi".
| Is This Answer Correct ? | 123 Yes | 33 No |
Answer / brindha.d
using session oject in jsp.
first u set using following methods
String name="ravi";
session.setAttribute("user",name);
using retrive method
String sessionuser=session.getAttribute(name);
out.println("welcome"+sessionuser);
u give this last 2 stmts in all jsp pages. it will
display as "Welcome ravi".
| Is This Answer Correct ? | 121 Yes | 55 No |
Answer / sandeep
Using HttpSession. Methods used are getSession(),
setAttribute and getAttribute
| Is This Answer Correct ? | 76 Yes | 17 No |
Answer / mainuddin
My declarring <%@ page session="true"%>
and setting one variable in request object
like.
<% String name="milu";%>
<% session.setAttribute("name",name);%>
getting this : <%=(String)session.getAttribute("name")%>
| Is This Answer Correct ? | 61 Yes | 11 No |
Answer / aryan
String name="Arpit";
session.setAttribute("user",name);
String sessionuser=session.getAttribute("user");
out.println("WellGud"+sessionuser);
| Is This Answer Correct ? | 36 Yes | 11 No |
Answer / mayur patel
start session oject in jsp.
first u set using following methods
String name="Mayur4453";
session.setAttribute("user",name);
using retrive method
String suser=session.getAttribute("user");**
out.println("Hi. . !! welcome "+suser);
| Is This Answer Correct ? | 19 Yes | 8 No |
Answer / murali mohan rao
first set the value in session using following methods
***Don't create the unnecessary Strings***
<%session.setAttribute("user","Murali");%>
Below statement you can use in any JSP to print the
welcome message. Start using JSP tags to better performance
and better coding.
<%= "Welcome to "+session.getAttribute("user")%>
| Is This Answer Correct ? | 12 Yes | 3 No |
Answer / murali mohan rao
first set the value in session using following methods
***Don't create the unnecessary Strings***
<%session.setAttribute("user","Murali");%>
Below statement you can use in any JSP to print the
welcome message. Start using JSP tags to better performance
and better coding.
Welcome to <%=session.getAttribute("user")%>
| Is This Answer Correct ? | 8 Yes | 3 No |
Answer / godfather
String str="xxx";
session.setAttribute("xxx",str);//to set session
//so nw the session will get store by the name "xxx".
//To retrieve session
String str1=session.getAttribute("xxx");
| Is This Answer Correct ? | 14 Yes | 10 No |
Answer / tarak
In the state page u have to set the session
<% Session ses=request.getSession(true);%>
Then set an atribute for the session.
<% ses.setAttribute("attribute","valid session");%>
Session: <% =ses.getAttribute("attribute");%>
(It will display Session: valid session)
Before you close or logout invlidate the session and remove
attribute
<% ses.removeAttribute("attribute");
ses.invalidate();%>
Everytime at the start of page we can check for the value
of sesion attribute. If it is set, then the session will be
valid. Otherwise invalid session.
| Is This Answer Correct ? | 2 Yes | 1 No |
How we can include the result of another page in jsp?
What is context url?
What is jsp life cycle?
Can you make use of a servletoutputstream object from within a jsp page?
What is jsp language?
What is welcome file list?
What are jsp implicit objects?
Why is it not recommended to use script elements in jsp?
What are the ways to insert java code into jsp page?
What is jsp and its advantages?
how to maintain sessions in jsp?can you tellme the methods.
16 Answers IBM, Scope International, TCS,
How to get value from java to jsp page?