tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Roubekas <p...@orthogroup.holdings>
Subject Re: Servlet <welcome-file-list> overridden by Apache Tomcat welcome page?
Date Sun, 03 Jul 2016 17:37:26 GMT
On 7/2/2016 4:24 PM, Paul Roubekas wrote:
> Servlet <welcome-file-list> overridden by Apache Tomcat welcome page?
>
>  
>
> Not sure I am using the proper name for what I am calling the "Apache
> Tomcat welcome page".  What I am calling the "Apache Tomcat welcome
> page" is the page that comes up when http://localhost:8080 is entered as
> the address on an internet browser.
>
>  
>
> Windows 7 (development workstation)
>
> Fedora 23 (web server)
>
> Apache Tomcat 7.0.68
>
> Apache TomEE 1.7.4
>
> Eclipse Mars 2 (4.5.2)
>
>  
>
> I have a single instance of Tomcat.  CATALINA_BASE is not used, just
> CATALINA_HOME.  The WEB-INF/web.xml has been configured as follows.
>
>  
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="http://java.sun.com/xml/ns/javaee"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
> version="3.0">
>
>  
>
>         <!-- ========================================================== -->
>
>         <!-- General Info -->
>
>         <!-- ========================================================== -->
>
>     <display-name>Abc</display-name>
>
>     <description>
>
>            The web site for Abc software
>
>     </description>
>
>  
>
>         <!-- ========================================================== -->
>
>         <!-- Home Servlet -->
>
>         <!-- ========================================================== -->
>
>     <servlet>
>
>        <servlet-name>HomeServlet</servlet-name>
>
>        <servlet-class>software.Abc.website.HomeServlet</servlet-class>
>
>        <load-on-startup>1</load-on-startup>
>
>      </servlet>
>
>  
>
>         <!-- Map the HomeServlet name to the URI /HomeServlet (main page
> for site) -->
>
>      <servlet-mapping>
>
>        <servlet-name>HomeServlet</servlet-name>
>
>        <url-pattern>/AbcLandingPage</url-pattern>
>
>      </servlet-mapping>
>
>  
>
>      <security-constraint>
>
>          <web-resource-collection>
>
>              <web-resource-name>Protect Donation page</web-resource-name>
>
>              <url-pattern>/DonateServlet</url-pattern>
>
>              <http-method>GET</http-method>
>
>              <http-method>POST</http-method>       
>
>          </web-resource-collection>
>
>          <user-data-constraint>
>
>              <transport-guarantee>CONFIDENTIAL</transport-guarantee>
>
>          </user-data-constraint>
>
>      </security-constraint> 
>
>  
>
>        
>
>         <!-- ========================================================== -->
>
>         <!-- Welcome Files -->
>
>         <!-- ========================================================== -->
>
>  
>
>         <!-- The main page for the site will be the HomeServlet servlet
> (http://website/AbcLandingPage) -->
>
>         <!-- No mapping is defined for other folders
> (http://website/someFolder/AbcLandingPage), -->
>
>         <!-- so one of the other files will be displayed (index.html,
> index.htm, index.jsp) -->
>
>         <welcome-file-list>
>
>             <welcome-file>AbcLandingPage</welcome-file>
>
>             <welcome-file>index.html</welcome-file>
>
>             <welcome-file>index.htm</welcome-file>
>
>             <welcome-file>index.jsp</welcome-file>
>
>         </welcome-file-list>
>
> </web-app>
>
>  
>
> As per these instructions
> (http://wiki.metawerx.net/wiki/HowToUseAServletAsYourMainWebPage) this
> configuration should result in the HomeServlet being the first page
> rendered when the URL http://myDomain.com is entered as the destination
> address in an internet browser.  But these instructions are generic for
> the Java Servlet 2.4 specification.  In this
> (http://wiki.apache.org/tomcat/HowTo#How_do_I_override_the_default_home_page_loaded_by_Tomcat.3F)FAQ
> for Tomcat it is suggest that meta tag refresh be used.  It seems the
> Tomcat meta tag refresh instruction were written before the Java Servlet
> 2.4 specification was written because other research
> (https://en.wikipedia.org/wiki/Meta_refresh) points out that the use of
> the meta tag refresh method is gone out of use because it can prevent
> the end user from being able to use the back button successfully and it
> is considered as one of the Un-ethical SEO process by the Search
> Engines.  The current version of the Java Servlet Specification is 3.0.
> (https://jcp.org/aboutJava/communityprocess/final/jsr315/index.html). 
>
>  
>
> Question 1) Is my assumption correct that the reason my web.xml is not
> working is because the Tomcat/Tomee welcome page is specified in such a
> way that it takes precedence over the web.xml settings in my websites
> .WAR file?
>
>  
>
> Question 2) Is there a way to have my .WAR file WEB-INF/web.xml take
> precedence over the Tomcat welcome page without uninstalling the Tomcat
> welcome page?

*For the sake of people who may search the forum archives, the answer is
provided below.*

There are changes that need to be made to the web.xml file and to the
server.xml file for this to work.

Changes that need to be made to the web.xml file.
The below list of changes are for the WEB-INF/web.xml file not the
server level conf/web.xml file.  A prerequisite is that the <servlet-name>
and <servlet-class> are in the <servlet> XML stanza.  The
<load-on-startup> XML element is not required for the task at hand.  It
was added
so the first user, after a tomee restart, did not experience poor
performance.
    <servlet>
       <servlet-name>HomeServlet</servlet-name>
       <servlet-class>software.abc.website.HomeServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
     </servlet>

A <servlet-mapping> XML stanza needs to be made also.  The
<servlet-name> in this <servlet-mapping> stanza must agree with the
<servlet-name> in the <servlet> stanza. The <url-pattern> does not need
to match the <servlet-name>.  The <url-pattern> tag must
match the <welcome-file> tag in the <welcome-file-list> stanza.
    <!-- Map the HomeServlet name to the URI /HomeServlet (main page for
site) -->
     <servlet-mapping>
       <servlet-name>HomeServlet</servlet-name>
       <url-pattern>/AbcLandingPage</url-pattern>
     </servlet-mapping>

A <welcome-file-list> stanza must also be added.  The <welcome-file>
entries are processed in the order listed.  The value for the
<welcome-file> must match the value for the <url-pattern> in the
<servlet-mapping> stanza earlier in the configuration file. In
this example the value is AbcLandingPage.
    <!-- so one of the other files will be displayed (index.html,
index.htm, index.jsp) -->
    <welcome-file-list>
        <welcome-file>AbcLandingPage</welcome-file>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

A complete web.xml file is listed below.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
version="3.0">

    <!-- ========================================================== -->
    <!-- General Info -->
    <!-- ========================================================== -->
    <display-name>Abc</display-name>
    <description>
       The web site for Abc software
    </description>

    <!-- ========================================================== -->
    <!-- Home Servlet -->
    <!-- ========================================================== -->
    <servlet>
       <servlet-name>HomeServlet</servlet-name>
       <servlet-class>software.abc.website.HomeServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
     </servlet>

    <!-- Map the HomeServlet name to the URI /HomeServlet (main page for
site) -->
     <servlet-mapping>
       <servlet-name>HomeServlet</servlet-name>
       <url-pattern>/AbcLandingPage</url-pattern>
     </servlet-mapping>

     <security-constraint>
         <web-resource-collection>
             <web-resource-name>Protect Donation page</web-resource-name>
             <url-pattern>/DonateServlet</url-pattern>
             <http-method>GET</http-method>
             <http-method>POST</http-method>       
         </web-resource-collection>
         <user-data-constraint>
             <transport-guarantee>CONFIDENTIAL</transport-guarantee>
         </user-data-constraint>
     </security-constraint> 

   
    <!-- ========================================================== -->
    <!-- Welcome Files -->
    <!-- ========================================================== -->

    <!-- The main page for the site will be the HomeServlet servlet
(http://website/AbcLandingPage) -->
    <!-- No mapping is defined for other folders
(http://website/someFolder/AbcLandingPage), -->
    <!-- so one of the other files will be displayed (index.html,
index.htm, index.jsp) -->
    <welcome-file-list>
        <welcome-file>AbcLandingPage</welcome-file>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

Changes that need to be made to the server.xml file
The below list of changes are for the conf/server.xml file.  A new XML
element needs to be added to the <Host> XML stanza.
Within the <Host> element stands a <Context> element needs to be added. 
The path= attribute for the <Context> element needs to be blank. 
The docbase= attribute needs to be equal to the .WAR file root
directory.  In this example Abc_Website03.  I'm not sure
the debug= attribute needs to be in the context element.  But I wasn't
going to spend time testing it.  I am also not sure
if the reloadable= attribute is required. But once again in the interest
of saving time it was not tested with the reloadable= attribute removed.
.
.
.
     <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <Context path="" docBase="Abc_Website03" debug="0"
reloadable="true"></Context>
.
.
.

A restart of the Tomee server is required for these changes to take
effect.  The Tomcat welcome page gets overridden automatically. 
In order to access the manager application going forward the URI,
http://999.999.999.999/manager/html, needs to be entered,
not just the domain name.


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message