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

How can we extend jsp technology?

0 Answers  


What are scripting elements?

0 Answers  


What is jsp application?

0 Answers  


What are request and response objects?

0 Answers  


what are the alternate way to use the scriplet in jsp.

1 Answers  






What is jsp index?

0 Answers  


Explain implicit objects in jsp?

0 Answers  


Explain the difference between servlet and jsp?

0 Answers  


When destroy method of jsp is called?

0 Answers  


What is a scriptlet in jsp and what is its syntax?

0 Answers  


What is the need for jsp?

0 Answers  


Can we call destroy method inside init method?

0 Answers  


Categories