Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

How to make a servlet "default page" in Tomca


I want "www.mydomain.com" to invoke one of servlets,
which means a servlet is my dafaut page.
Conventionally, servlet is invoked by calling
www.mycomain.com/servlet/MyServlet.
Does anybody know how to configure??
I am using Tomcat only. I can use Apache if needed.
Please help.
0
jhy
Asked:
jhy
  • 2
  • 2
1 Solution
 
bobbit31Commented:
in your web.xml put something like this:
    <servlet>
        <servlet-name>
            MyServlet
        </servlet-name>
        <servlet-class>
            com.package.MyServlet        
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>
            MyServlet
        </servlet-name>
        <url-pattern>
            index.html
        </url-pattern>
    </servlet-mapping>
0
 
girionisCommented:
 It depends on what version of tomcat you are using. I am not sure about the latest Cataline one but in the older versions you can define it in your web.xml file:

<welcome-file-list>
    <welcome-file>default.html</welcome-file>
</welcome-file-list>

  You can redirect to the servlet from your default file.

  Additionally you can also use the <servlet-mapping> tag, but I have not used Tomcat for ages, so someone else might be able to help you more.

  Hope it helps.
0
 
bobbit31Commented:
the servlet mapping works on both tomcat 3.2.* and tomcat 4.0
0
 
girionisCommented:
 I see... I have not used Tomcat since its 3.2 version... I know that Catalina is a completely new architecture so I was not sure if the <servlet-mapping> and <servlet> still work the same. To be honest I am not 100% sure even for the <welcome-file-list>.

  Kind regards
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now