Sometimes it is desireable to use a servlet to handle session logic. In
complex systems, it is not a good idea to have lots of java code
in the JSP pages. Having too much low level logic in the presentation
defeats the purpose of JSPs. For instance, when obtaining a reference to a
database connection object (java.sql.Connection), the whole process (
registering the driver, asking for a connection, storing it's reference as a
session parameter) can be handled by a servlet that the JSP page has access
to. (A servlet can also be used as a bean, where a servlet generated from a
JSP cannot) This separates underlying logic (Session object handling) from
the presentation.


-----Original Message-----
From: Rakesh Bhat [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 07, 2000 11:51 PM
To: [EMAIL PROTECTED]
Subject: Re: session


Hi Laskowski,

As I understand , one uses JSP over Servlet because writing a JSP code is
simpler
compared to Servlet.Right ?
They are 2 different server side technologies.
I agree that JSP finally compiles into a Servlet.But , i don't understand
why one
will use JSP and servlet together ?
When you use JSP , all the objects like request , session... are available
implicitly which you get in servlet by extending HTTPServletRequest class.
right ?
So why one will use Servlet with JSP? As I understand one uses Java code in
a
separate bean because he/she wants to hide the business logic. Right ? Why
to keep
the same code in a servlet ?
Is my thinking correct or am i missing here something ?

Thx in advance
Rakesh.




Jacek Laskowski wrote:

> Angela Chow wrote:
> >
> > thanks for your reply :)
> >
> > i am very new to this concept.  Is there anywhere that
> > i can learn a little bit more about this?  I've notice
> > that Tomy Wong has put some code on his reply:
> >
> > HttpSession session = HttpServletRequest.getsession();
> > session.putValue("listenerobjcet",listener);
> > HttpSessionBindingEvent sessionbind = new
> > HttpSessionBindingEvent(session,"listener");
> > session.removeValue("listener");
> >
> > I don't know where to put this code, is the jsp page,
> > or in the bean?  If in the jsp page, is it on every
> > page?  How do i set the length of time for the
> > time-out?  I am getting little confused.  Please help
> > me out!
>
> I'd suggest that any Java code puts either in Tag Extensions or
> servlets. Going even a little further, try to follow Model 2 ideas.
> Create *one* servlet controller which controls who should do what. In
> that case, all JSPs do is only to display beans' state.
>
> To answer your question(s), just put it inside servlet controller, so
> the following JSP pages can use it. After that, just forward request to
> JSP to display it. When you becomes more familiar with that approach,
> you won't have to search all your code, just to check out whether
> everything is right. All you'll have to do is to open *one* servlet
> controller and modify it as you wish.
>
> Simple ? Yes, it should be:)
>
> >
> > angela
>
> Jacek Laskowski
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to