how to maintain sessions in jsp?can you tellme the methods.

Answers were Sorted based on User's Feedback



how to maintain sessions in jsp?can you tellme the methods...

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

how to maintain sessions in jsp?can you tellme the methods...

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

how to maintain sessions in jsp?can you tellme the methods...

Answer / sandeep

Using HttpSession. Methods used are getSession(),
setAttribute and getAttribute

Is This Answer Correct ?    76 Yes 17 No

how to maintain sessions in jsp?can you tellme the methods...

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

how to maintain sessions in jsp?can you tellme the methods...

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

how to maintain sessions in jsp?can you tellme the methods...

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

how to maintain sessions in jsp?can you tellme the methods...

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

how to maintain sessions in jsp?can you tellme the methods...

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

how to maintain sessions in jsp?can you tellme the methods...

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

how to maintain sessions in jsp?can you tellme the methods...

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

Post New Answer

More JSP Interview Questions

Which implicit object is not available in normal jsp pages?

0 Answers  


What is the advantage of using getProperty action, as compared to the accessor method?

0 Answers  


What is session setattribute?

0 Answers  


Differentiate between <jsp:include page=…> and <%@include file=…>.

0 Answers  


What are different types of comments in jsp?

0 Answers  






Is jsp platform dependent?

0 Answers  


how can i get a scjp certification??

3 Answers  


How can I use jsp in the mvc model?

0 Answers  


Explain the jsp:setProperty action.

0 Answers  


What do you mean by context initialization parameters?

0 Answers  


Which jsp life cycle is in correct order?

0 Answers  


Which jsp lifecycle methods can be overridden?

0 Answers  


Categories