MAP | PageMixer Documents > Tutorial > Mixing with Servlet > Forward control | << | >> |
This section explains
how to customzie control forwarding
with PageServlet
.
You can skip this section if you have no interest to forward control to another page.
Class diagram in this section is shown below:
Classes which you must define are colored, and other are already defined.
In this tutorial, abbreviated class names are used. Complete names are shown below.
Notation | Full name |
---|---|
ConsumerContext | jp.ne.dti.lares.foozy.pagemixer.mixer.ConsumerContext |
ForwardCondition | jp.ne.dti.lares.foozy.pagemixer.servlet.ForwardCondition |
ForwardStrategy | jp.ne.dti.lares.foozy.pagemixer.servlet.ForwardStrategy |
PageServlet | jp.ne.dti.lares.foozy.pagemixer.servlet.PageServlet |
RequestKey | jp.ne.dti.lares.foozy.pagemixer.servlet.RequestKey |
SessionKey | jp.ne.dti.lares.foozy.pagemixer.servlet.SessionKey |
No tutorial specific class is explained in this section.
Sometime you may want to forward control from one Servlet to another. For example, you will want to forward control from member limited pages to login form page.
Separating the control forward logic from HTTP response renderring allows you to:
ForwardCondition
PageMixer provides "ForwardStrategy
"
for customization of control forwarding.
But in fact,
ForwardStrategy
default implementation does not determine
whether control should be forwarded to another Servlet.
ForwardStrategy
asks "ForwardCondition
"s,
which are registered to itself.
ForwardCondition
has the method to accept inquiry
whether control should be forwarded or not,
and where if it should,
as shown below.
public String forwards(ConsumerContext context)
This should return non-null value as forwarding destination when control should be forwarded, or return null otherwise. Sample implementation is shown below:
if(null == context.getValue(KEY_LOGIN)){ context.setValue(KEY_LOGIN_REQUIRED, KEY_LOGIN_REQUIRED); return authPage_; } return null;
In this example,
KEY_LOGIN
and KEY_LOGIN_REQUIRED
are instance of
SessionKey
to identify value which is set when user already login,
and
RequestKey
to indicate whether user try to access member limited page or not.
You may also want to determine forwarding destination
not at compiling but at configuration.
In this example, it is held in authPage_
.
ForwardCondition
also provides
setup
method for initialization of classes derived from it,
and defult implementation of it does nothing.
Overriding example of it is shown below:
public void setup(HttpServlet servlet) throws ServletException // { super.setup(servlet); ServletContext context = servlet.getServletContext(); authPage_ = context.getInitParameter(INIT_PAGE_AUTH); if(null == authPage_){ throw new ServletException(INIT_PAGE_AUTH); } }
INIT_PAGE_AUTH
has value to look up the context parameter,
which is path of login(= authentication) page.
So, you can forward control to login page
if your custom ForwardCondition
returns authPage_
.
Please see API document for detail to
concretize ForwardCondition
and/or
override ForwardStrategy
.
ForwardStrategy
accepts
Servet initialize parameter(s) shown below:
name | description |
---|---|
forward.condition. N |
name of ForwardCondition implement class.
"N" is 0 origin number.
you can specify multiple ForwardCondition s. |
To use your custom ForwardStrategy
,
you should specify "servlet.forwardStrategy
"
Servlet init-param in deployment descriptor
as shown below.
<init-param>
<param-name>
servlet.forwardStrategy
</param-name>
<param-value>
name of your custom ForwardStrategy
</param-value>
</init-param>
MAP | PageMixer Documents > Tutorial > Mixing with Servlet > Forward control | << | >> |