In GWT I'd like to load the main page on www.domain.com and a dynamic page on www.domain.com/xyz - I
- by Mike Brecht
Hi,
I have a question for which I'm sure there must a simple solution. I'm writing a small GWT application where I want to achieve this:
www.domain.com : should serve the welcome page
www.domain.com/xyz : should serve page xyz, where xyz is just
a key for an item in a database. If there is an
item associated with key xyz, I'll load that and show a page, otherwise I'll show a
404 error page.
I was trying to modify the web.xml file accordingly but I just couldn't
make it work. I could make it work with an url-pattern if the key in question is after another /, for example: www.domain.com/search/xyz. However,
I'd like to have the key xyz directly following the root / (http://www.domain.com/xyz).
Something like
<servlet-mapping>
<servlet-name>main</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
doesn't seem to work as I don't know how to address the main page
index.html (as it's not an actual servlet) which will then load my
main GWT module.
I could make it work with a bad work around (see below): Redirecting a
404 exception to index.html and then doing the look up in the main
entry point, but I'm sure that's not the best practice, also for SEO
purposes.
Can anyone give me a hint on how to configure the web.xml with GWT for
my purpose?
Thanks a lot.
Mike
Work-around via 404:
Web.xml:
<web-app>
<error-page>
<exception-type>404</exception-type>
<location>/index.html</location>
</error-page>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
index.html -- Main Entry point -- onModuleLoad():
String path = Window.Location.getPath();
if (path == null || path.length() == 0 || path.equalsIgnoreCase("/")
|| path.equalsIgnoreCase("/index.html")) {
... // load main page
} else {
lookup(path.substring(1)); // that's key xyz