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 |
What is the purpose of creating custom tags?
What is the different between servlet and struts
Can we define a class inside a jsp page?
What is jsp net?
What are custom tags in jsp?
What is an expression in jsp?
What is the page directive is used to prevent a jsp page from automatically creating a session?
Mention the implicit objects in a jsp.
Why are jsp pages preferred for creating web-based client program?
What is expression language in jsp?
What is iselignored in jsp?
What is el in jsp?