You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by suhas <su...@techmas.hcltech.com> on 2001/07/23 12:59:52 UTC

Basic Question in Servlet/JSP ?

Hi 
 
The PageContext instance gives us access to implicit objects in the page
.This is used mainly in JSP . Why Can't we have something in the Servlet
?

Why to directly use HttpServletRequest , HttpSession in the Servlet ?
Better can't we get this from the container specific implementaion
something like PageContext in the Servlet too? . 
 
Regards
 
 


Re: Basic Question in Servlet/JSP ?

Posted by Ted Husted <hu...@apache.org>.
To access the request in a Struts Action, you would reference the
"request" passed to the perform() method. 

    public ActionForward perform(ActionMapping mapping,
                 ActionForm form,
                 HttpServletRequest request,    //  <--- request
                 HttpServletResponse response)

To access the session, you would code 

        HttpSession session = request.getSession();


-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/

suhas wrote:
> 
> I was not referring to Struts . We have something like PageContext in the
> JSP . which we use to set some information using setAttribute method in
> either Request scope or  Session scope . Instead same could have done with
> the
> request.setAttribute( "key" val) or session.setAttribute("key" , val ) .
> My question was why we have not provided with few implicit objects like
> session , out etc.. in the Servlet's ???
> Why this concept came only in JSP ? .
> 
> Suhas

Re: Basic Question in Servlet/JSP ?

Posted by suhas <su...@techmas.hcltech.com>.
I was not referring to Struts . We have something like PageContext in the
JSP . which we use to set some information using setAttribute method in
either Request scope or  Session scope . Instead same could have done with
the
request.setAttribute( "key" val) or session.setAttribute("key" , val ) .
My question was why we have not provided with few implicit objects like
session , out etc.. in the Servlet's ???
Why this concept came only in JSP ? .

Suhas



----- Original Message -----
From: Ted Husted <hu...@apache.org>
To: <st...@jakarta.apache.org>
Sent: Monday, July 23, 2001 4:43 PM
Subject: Re: Basic Question in Servlet/JSP ?


> If you're referring to the PageContext that is available when you are
> rendering the view, the answer would be because it doesn't exist yet ;-)
> The Struts ActionController (a servlet) calls an Action (not a servlet),
> and may eventually forwards to a JSP (another servlet). The PageContext
> for the JSP isn't available until it is called. The mechanism for
> carrying information between HTTP forwards is the HttpServletRequest, or
> the session to carry it between requests.
>
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Custom Software ~ Technical Services.
> -- Tel 716 737-3463.
> -- http://www.husted.com/about/struts/
>
>
> > suhas wrote:
> >
> > Hi
> >
> > The PageContext instance gives us access to implicit objects in the
> > page
> > .This is used mainly in JSP . Why Can't we have something in the
> > Servlet
> > ?
> > Why to directly use HttpServletRequest , HttpSession in the Servlet ?
> > Better can't we get this from the container specific implementaion
> > something like PageContext in the Servlet too? .
> >
> > Regards
> >
> >
>


Re: Basic Question in Servlet/JSP ?

Posted by Ted Husted <hu...@apache.org>.
If you're referring to the PageContext that is available when you are
rendering the view, the answer would be because it doesn't exist yet ;-)
The Struts ActionController (a servlet) calls an Action (not a servlet),
and may eventually forwards to a JSP (another servlet). The PageContext
for the JSP isn't available until it is called. The mechanism for
carrying information between HTTP forwards is the HttpServletRequest, or
the session to carry it between requests.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/


> suhas wrote:
> 
> Hi
> 
> The PageContext instance gives us access to implicit objects in the
> page
> .This is used mainly in JSP . Why Can't we have something in the
> Servlet
> ?
> Why to directly use HttpServletRequest , HttpSession in the Servlet ?
> Better can't we get this from the container specific implementaion
> something like PageContext in the Servlet too? .
> 
> Regards
> 
>