I want to create a session and set user's name after users successfully log in:
HttpSession session = request.getSession( );
if ( session.isNew() )
{
student.setName(request.getParameter("username"));
session.setAttribute("student", student);
}
I have a number of servlets and JSPs in my application. I hesitate to create the session object in a JSP because JSP is presentation centric. Do I have to create session objects in a servlet?
Originally posted by Marty Hall:
...
The system automatically creates session in JSP pages and binds them to the predefined _jspService local variable called "session". This is true except if you do <%@ page session="false" %> (which does not disable session tracking, but merely prevents the JSP page from making a new session if it didn't already exist).
...
Juan Rolando Prieur-Reza, M.S., LSSBB, SCEA, SCBCD, SCWCD, SCJP/1.6, IBM OOAD, SCSA
Does it mean that I can code
in one of my JSP. Later on, I can retrieve the String s from the session object in one of my "other" JSPs or servlets?
Originally posted by JiaPei Jen:
I want to create a session and set user's name after users successfully log in:
HttpSession session = request.getSession( );
if ( session.isNew() )
{
student.setName(request.getParameter("username"));
session.setAttribute("student", student);
}
I have a number of servlets and JSPs in my application. I hesitate to create the session object in a JSP because JSP is presentation centric. Do I have to create session objects in a servlet?
Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Originally posted by Pradeep Bhat:
For the first question the answer is yes.
JSP is used for presentation purpose, so java is to be avoided. This makes it easier for a web developer who doesn't know java. Expression language helps to avoid all java code . It syntax is similar to javscript making it easier for someone who know JS to pick up the langauge very quickly.
Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Always look on the bright side of life. At least this ad is really tiny:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|