MAP | PageMixer Documents > Tutorial > Mixing with Servlet > Identify value for Servlet | << | >> |
This section explains how to identify values for Servlet.
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 |
---|---|
ApplicationKey | jp.ne.dti.lares.foozy.pagemixer.servlet.ApplicationKey |
ConsumerContext | jp.ne.dti.lares.foozy.pagemixer.mixer.ConsumerContext |
ContextInitKey | jp.ne.dti.lares.foozy.pagemixer.servlet.ContextInitKey |
CookieKey | jp.ne.dti.lares.foozy.pagemixer.servlet.CookieKey |
HashMapConsumerContext | jp.ne.dti.lares.foozy.pagemixer.mixer.HashMapConsumerContext |
ParameterKey | jp.ne.dti.lares.foozy.pagemixer.servlet.ParameterKey |
ReqHeaderKey | jp.ne.dti.lares.foozy.pagemixer.servlet.ReqHeaderKey |
RequestKey | jp.ne.dti.lares.foozy.pagemixer.servlet.RequestKey |
ResHeaderKey | jp.ne.dti.lares.foozy.pagemixer.servlet.ResHeaderKey |
ServletConsumerContext | jp.ne.dti.lares.foozy.pagemixer.servlet.ServletConsumerContext |
ServletInitKey | jp.ne.dti.lares.foozy.pagemixer.servlet.ServletInitKey |
SessionKey | jp.ne.dti.lares.foozy.pagemixer.servlet.SessionKey |
No tutorial specific class is explained in this section.
Now, you already know that
you can identify the value in ConsumerContext
by key Object
.
ATTENTION: Please see "Mixing with PageMixer" at first, if you have not learn how to use PageMixer yet.
You can choose any objects to identify values in stand alone application environment: java.lang.String , for example. But mixing with Servlet, you will want to get/set/unset Servlet environment specific values, for example, which are given by:
HttpServlet#getInitParameter
HttpServletRequest#getParameter/getParameterValues
HttpServletRequest#getAttribute
HttpServletRequest#getHeader/getHeaders
HttpServletResponse#setHeader
HttpSession#getAttribue
Cookie#getValue
ServletContext#getAttribute
ServletContext#getInitParameter
PageMixer provides
classes to identify above values in ConsumerContext
shown below(please see "servlet" package description for complete list)
ServletInitKey
ParameterKey
RequestKey
ReqHeaderKey
ResHeaderKey
SessionKey
CookieKey
ApplicationKey
ContextInitKey
For example, you can get/set/unset value in request attribute by key object shown below.
Object key = new RequestKey("name of attribute");
Accesing value by this key
causes getAttribute()
, setAttribute()
and/or removeAttribute()
of HttpServletRequest
.
ConsumerContext
ServletConsumerContext
By classes described above
work correctly with ServletConsumerContext
.
You can get/set/unset values by them without any other configuration
except of correct ServletConsumerContext
construction.
Please attention that
some classes do not support some of get/set/unset functions
because of Servlet API restriction.
For example,
you can not set/unset value by
ParameterKey
.
ConsumerContext
For other ConsumerContext
implementation classes,
it depends on implementation of it
wether classes described above work correctly with them or not.
At least,
they work with HashMapConsumerContext
correctly,
because they, key classes, override
Object#equals
and Object#hashCode
.
But with HashMapConsumerContext
,
invalid use(set valu by ParameterKey
,
for example) of them does not cause
UnsupportedOperationException
raising.
even though
invalid use with ServletConsumerContext
causes so.
So, 'work correctly' means that they can 'identify values correctly'.
MAP | PageMixer Documents > Tutorial > Mixing with Servlet > Identify value for Servlet | << | >> |