|
PageMixer API - 3.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jp.ne.dti.lares.foozy.pagemixer.servlet.ServletUtil
Ulitiy class for Servlet environment.
Constructor Summary | |
ServletUtil()
|
Method Summary | |
static java.lang.String |
getBaseHref(ConsumerContext context,
boolean useHostHeader,
boolean useContextRoot)
Utility to get href value of base HTML tag. |
static java.lang.String |
getBaseHref(javax.servlet.http.HttpServletRequest request)
Deprecated. by getBaseHref(ConsumerContext, boolean, boolean) |
static java.lang.String |
getHostName(ConsumerContext context,
boolean ensure)
Utility to get host name of servlet container. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ServletUtil()
Method Detail |
public static java.lang.String getBaseHref(ConsumerContext context, boolean useHostHeader, boolean useContextRoot)
This method composes value for
"href
" of "base
"
from:
RequestMethodKey.SCHEME
ReqHeaderKey.HOST
or
RequestMethodKey.SERVER_NAME
RequestMethodKey.SERVER_PORT
(if useHostHeader
is false)
RequestMethodKey.CONTEXT_PATH
or RequestMethodKey.REQUEST_URI
When you specify useHostHeader
as false,
you should attention that
this method composes href
value of base
tag
not from client side information(e.g.: HTTP request headers)
but from server side configuration.
This may causes unexpected location using
in tunneling/port-forwarding environment or
virtual hosting.
For example,
when port #80 on your local host is
forwarded to port #80 of server host via secure channel(e.g.: via SSH),
you can not access any related resources
from page with base
tag,
because its href
value has not your local host
but server host.
So, your browser will try to load resources from server host
via unexpected channel.
When you specify useContextRoot
as true,
this method composes href
value
not from requested URI, but from Servlet context path.
For example,
assumption is that your web application is mounted on
"/myApp", and requested URL is
"http://foo.com/myApp/bar.servlet
".
This method returns
"http://foo.com/myApp/
"
if useContextRoot
is true,
or "http://foo.com/myApp/bar.servlet
" otherwise.
Former value allows you to specify resouce location in response HTML page not relatively to request URI, but relatively to Servlet context(= web application).
This uses
URL
to compose "href" value.
request
- of current request contextuseHostHeader
- as part of URL if it is specifieduseContextPath
- whether RequestMethodKey.CONTEXT_PATH
is used instead of RequestMethodKey.REQUEST_URI
or notpublic static java.lang.String getBaseHref(javax.servlet.http.HttpServletRequest request)
getBaseHref(ConsumerContext, boolean, boolean)
This is equivalent to
getBaseHref(context, false, false)
.
request
- of current request contextpublic static java.lang.String getHostName(ConsumerContext context, boolean ensure)
At first, this tries to get "host name"
from context by ReqHeaderKey.HOST
.
Then, this tries to get by RequestMethodKey.SERVER_NAME
,
if (1)"ensure" is true and
(2)context has no value for ReqHeaderKey.HOST
.
In other words,
this tries to get host name
by HttpServletRequest#getServerName()
,
when "host" header is not specified in this context.
This may contain port number to which http client tries to connect, because "host" request header may does so.
context
- in which information is looked upensure
- or not non-null return value
|
PageMixer API - 3.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |