Difference between version and version      View first change»»

Back to HowToUseAServletAsYourMainWebPage, or HowToUseAServletAsYourMainWebPage version history

At line 1 changed 3 lines.
[{ALLOW edit Asserted,Authenticated}]
[{ALLOW upload Asserted,Authenticated}]
[{ALLOW rename Asserted,Authenticated}]
[{ALLOW edit neale}]
[{ALLOW upload neale}]
[{ALLOW rename neale}]
At line 70 added 2 lines.
* As the path for <[welcome-file|web.xml.WelcomeFile]> is relative (and cannot be absolute), a servlet can only be used as the main page of the application, and not a welcome file for every folder. This is the same for other index files such as index.htm, in that they cannot refer to a single index.htm file, but instead cause Tomcat to search the specified folder for a file called "index.htm". Even if you map the servlet as *.foo, a <[welcome-file|web.xml.WelcomeFile]> of index.foo will not work (at least in Tomcat versions up to and including 5.5.23 and 6.0.13). One workaround is to also specify a <[url-pattern|web.xml.URLPattern]> mapping for /someFolder/MyServlet (where /someFolder is the folder you want to use the servlet in, and /MyServlet is your <[url-pattern|web.xml.URLPattern]>). Another way to make the servlet work as a default for any folder is to change the [Default Servlet] instead.
\\
At line 126 added 30 lines.
!How to use a Servlet as your main page in Servlets 2.3 and lower
If you are using servlets 2.3 or lower, you can point to a JSP file instead, and make that file redirect to your servlet. eg:
File redirect.jsp (where /CMS is mapped to your servlet, as in the above examples)
{{{
<%
response.sendRedirect("http://yoursite.com/CMS");
%>
}}}
Welcome-file list in web.xml:
{{{
<!-- The main page for the site will be redirect.jsp servlet, which redirects -->
<!-- to the MyCMS servlet (http://yoursite.com/CMS) -->
<!-- No mapping is defined for other folders (http://website/someFolder/CMS), -->
<!-- so one of the other files will be displayed (index.html, index.htm, index.jsp) -->
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
}}}
!Troubleshooting
* Make sure you don't use leading slashes on your <[welcome-file-list|web.xml.WelcomeFileList]> files (eg: use CMS, not /CMS)
* If using the servlet in a <[welcome-file-list|web.xml.WelcomeFileList]>, make sure your [web.xml] version is 2.4 or above (see [web.xml - DTD and XSD]), and that you are using a 2.4 compliant container or above (eg: Tomcat 5.5 or above)
\\
navigation
metawerx specific
search
Share
tools
help

referring pages

Share