Servlet as a welcome file: is it a myth?

Hello
There are many articles on the web that espouse that Servets 2.4 allow for a servlet to be specified as a welcome file thusly (taken from OnJava.com):
First, register the servlet in web.xml.
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
"http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<servlet>
<servlet-name>MyServlet</servlet-name.
<servlet-class>com.jspservletcookbook.MyServlet</servlet-class>
</servlet>
<!-- optionally map the 'MyServlet' servlet to a URL pattern -->
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/myservlet</url-pattern>
</servlet-mapping>
<!-- rest of web.xml ... -->
Then create a welcome-file element in web.xml that specifies the registered servlet name.
<welcome-file-list>
<welcome-file>MyServlet</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
Make sure to use the servlet name in the welcome-file element without a forward slash (/) preceding it.
Poppycock I say. At least it's not working for me with either Tomcat 5 or Tomcat 5.5. Has anyone out there ever seen this work on Tomcat?

It most certainly is possible now, but wasn't until rather late in TC 5.0.xx series I believe (5.0.18 or so?). You can chack the change logs to id exactly when...
But the reason it isn't working for you is you have to match the value in your <welcome-file> to the URL in the servlet's <url-pattern> servlet mapping. So your web XML should look like this:
<servlet>
  <servlet-name>MyServlet</servlet-name.
  <servlet-class>com.jspservletcookbook.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>MyServlet</servlet-name>
  <url-pattern>/myservlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
  <welcome-file>myservlet</welcome-file>
  <welcome-file>default.jsp</welcome-file>
</welcome-file-list>Your porblem was case. Your url-pattern had lower case, but the welcome-file had upper case letters like the servlet name.
Here is an example app that I tested and worked:
//The servlet:
package net.thelukes.steven;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class WelcomeServlet extends HttpServlet {
     public void doGet(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
          PrintWriter out = response.getWriter();
          out.println("Hello World");
          out.flush();
          out.close();
//the web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     <display-name>WTPTest</display-name>
     <servlet>
          <servlet-name>Welcome</servlet-name>
          <servlet-class>net.thelukes.steven.WelcomeServlet</servlet-class>
     </servlet>
     <servlet-mapping>
          <servlet-name>Welcome</servlet-name>
          <url-pattern>/welcome</url-pattern>
     </servlet-mapping>
     <welcome-file-list>
          <welcome-file>welcome</welcome-file>
     </welcome-file-list>
</web-app>
//The address I typed (the web app is names WTPTest
http://localhost:8080/WTPTest
//The HTML Output
Hello World

Similar Messages

  • Can I use servlet as my welcome file

    How can I use servlet as my welcome file? I know how to use jsp or html pages as my welcome file but that doesn't work for servlets. I modified my web.xml for making jsps and html as my welcome pages but that <welcome-file-list> tag is not working for servlets.

    This was a bug that occured in older Tomcat programs, not sure if it still occurs or not.
    Basically, when this happens, you have to have a physical file with the welcome file name. So you would have to create a file named index.do in each of your directories you wanted the welcome to work for. The index.do wouldn't have to actually do anything. It just had to exist. Then when the URL was used to create content, the servlet would be called to create that content.

  • How to set two different welcome-file to different servlets in web.xml

    Hi friends,
    Can some one help with web.xml file
    I have to different servlets in applications.
    I want to set two different welcome files for my two different
    servlets in web.xml
    Please, can some one give me sample code to achieve this.
    Here web.xml code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>     
         <servlet>
              <servlet-name>reports</servlet-name>
              <servlet-class>com.caremark.ivr.servlet.IvrReportsServlet</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>reports</servlet-name>
              <url-pattern>/reports</url-pattern>
         </servlet-mapping>
         <session-config>
              <session-timeout>30</session-timeout>
         </session-config>
         <welcome-file-list>
              <welcome-file>reportsindex.jsp</welcome-file>
         </welcome-file-list>
         <servlet>
              <servlet-name>calldetails</servlet-name>
              <servlet-class>com.caremark.ivr.servlet.IvrCallDetailsServlet</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>calldetails</servlet-name>
              <url-pattern>/calldetails</url-pattern>
         </servlet-mapping>
    <welcome-file-list>
              <welcome-file>calldetailsindex.jsp</welcome-file>
         </welcome-file-list>
    </web-app>
    I need this fix immediately. Your help will be really appreciated. Thanks in advance.

    First of all, my understanding is that you need to have a Servlet 2.4 complaint server to do this...Given that, you're supposed to be able to simply specify the Name of the servlet as the welcome-file to get it to work. For example:
    Your servlet section:
    <servlet>
      <servlet-name>Controller</servlet-name>
      <servlet-class>com.company.ControllerServlet</servlet-class>
    </servlet>Now you would add the following to your welcome file list:
    <welcome-file-list>
      <welcome-file>Controller</welcome-file>
    </welcome-file-list>Note that you use the servlet-name value from the servlet definition, NOT the url-mapping from the servlet-mapping section.
    Please note that I cannot verify this as I am running a 2.3 server at home. When I get to work Friday I can test on a 2.4 machine. However this shouldn't take you more than a minute to test.
    Note that I did try this on the 2.3 compliant server and it did NOT work (as I expected)...
    HTH.

  • Putting Servlet as welcome file

              Hello, I'm playing with struts example on weblogic 7.
              When I specify my servlet in my welcome-file list, the webserver gave me a 403
              error.
              For instance, if i try
              http://localhost:7001/myapp/
              it will give me a HTTP 403 error.
              if i try
              http://localhost:7001/myapp/logon.do
              it works.
              So is there someway I can configure weblogic 7 to
              accept servlet as welcome file?
              Thanks.
              /* my xml file */
              <servlet-name>action</servlet-name>
              <servlet-lass>
              org.apache.struts.action.ActionServlet
              </servlet-class>
              <servlet-mapping>
              <servlet-name>action</servlet-name>
              <url-pattern>*.do</url-pattern>
              </servlet-mapping>
              <welcome-file-list>
              <welcome-file>hello.do</welcome-file>
              </welcome-file-list>
              /** end of xml code */
              

    If you have a proxy in front of WLP, you can have whatever url you like set as
    the default to forward on to your .portal.
    Alternatively, can you not specify the welcome page in the web.xml file?
    "Karthi" <[email protected]> wrote:
    But Kunal,
    It will cause the URL to change right ?
    I don't want to URL to change
    Otherwise, if we have www.foo.com then,
    How it can point to www.foo.com/home.portal but the URL should not change.
    Is there any way.??
    Karthi.
    "Kunal Mittal" <[email protected]> wrote in message
    news:40e2f351$1@mktnews1...
    One way is to configure an index.html as the welcome file. This index.htmlcan
    do a meta redirect to the url for the desktop or the .portal file.
    "Karthi" <[email protected]> wrote:
    Hi all ,
    How can we configure .portal file as welcome file in Weblogic 8.1
    SP2
    portal
    Thanks,
    Karthi

  • How to use dynamic file as welcome-file-list in web.xml

    I have configured my web.xml file as this,
    <web-app>
    <context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
    </context-param>
    <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>login.jsf</welcome-file>
    </welcome-file-list>
    </web-app>
    and my login.xhtml file as this,
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:c="http://java.sun.com/jstl/core"
    xmlns:f="http://java.sun.com/jsf/core">
    <body>
    <f:view>
    <h:form>
    UserName:<h:inputText id="userName"
    value="#{bean.userName}" rendered="true"
    required="true"/>
    Password:<h:inputText id="password"
    value="#{bean.password}" rendered="true"
    required="true"/>
    <h:commandButton id="submit" value="Submit" action="#{bean.authenticate}" />
    </h:form>
    </f:view>
    </body>
    </html>
    but when i deploy this using tomcat and try to put url as this,
    http://localhost:8080/project
    Its not identifying welcome file from web.xml
    I am getting error like this,
    The requested resource (/project/) is not available.
    How to resolve this,
    Thanks,
    Vinutha

    This might help:
    http://forum.java.sun.com/thread.jspa?threadID=696586
    As well, you might have to change the servlet-mapping in your web.xml. The url-pattern, I think, needs to be .xhtml. Your login.jsf file in the welcome list will need to be renamed to login.xhtml.
    CowKing

  • 8.1 EE can't find page and appends the welcome-file name to the url

    I have a problem where you enter a url that points to a static file in the xxxEar-WebModule_war directory. That is the "docroot" directory for the application. Somewhere along the line the welcome-file (index.html) is appended to the url. For example I enter http://server.com/app/file.xml and it gets changed to http://server.com/app/file.xml/index.html, which is not found.
    This was not a problem in 8.1 platform. Now that we upgraded to 8.1 enterprise it is a problem.
    All urls that are mapped to servlets work fine. I just can't seem to access static content.
    Thanks!

    select l.group#, f.member, l.sequence#, l.status, f.status
    from v$log l, v$logfile f
    where l.group#=f.group#
    order by 1;
    GROUP#
    MEMBER
    SEQUENCE# STATUS STATUS
    1
    D:\ORACLE\ORADATA\DBMAG98\LOG1.RDO
    41002 INACTIVE STALE
    2
    D:\ORACLE\ORADATA\DBMAG98\LOG2.RDO
    41003 INACTIVE
    GROUP#
    MEMBER
    SEQUENCE# STATUS STATUS
    3
    D:\ORACLE\ORADATA\DBMAG98\LOG3.RDO
    41004 CURRENT STALE
    sorry for inconvenient view

  • Welcome file usage: can it be any URL?

    Hi,
    Do welcome-files have to always be concrete files such as .html or .jsp files? I am finding that when using Tomcat 4.0.1, if I specify a servlet mapping as a welcome file, I end up getting a directory listing.
    For example, since I am using Struts, I have specified a Struts action as my welcome-file, but Tomcat seems to ignore this altogether and I end up getting a directory listing. If I request the action directly, then I have no problems.
    Has anyone faced any similar issues?
    Regards,
    Steve

    Hi,
    I am also running into the same issue.
    Did you get any workaround?
    Please let know,
    thanx in advance
    -Pravir

  • Welcome file and Jsp compiled

    Hi,
    I have very problems with compiled JSP. I work with tomcat 4.0.1.
    1) When I compile JSP with jspc and -webapp option and -webinc,
    he creates a file xml as :
         <servlet>
    <servlet-name>.hdi_0005faideResolveur</servlet-name>
    <servlet-class>.hdi_0005faideResolveur</servlet-class>
         </servlet>
         <servlet-mapping>
    <servlet-name>.hdi_0005faideResolveur</servlet-name>
    <url-pattern>/jsp/Pastel/doc/hdi_aideResolveur.jsp</url-pattern>
         </servlet-mapping>
    It don't work. I need to modify "-class>." in "-class>".
    Is it normal ?????????
    2) In web.xml, I have define a welcome-file as :
    <welcome-file-list>
    <welcome-file>/jsp/Pastel/hdi_index.jsp</welcome-file>
    </welcome-file-list>
    When I work in un-compile Jsp, It's work well.
    But, with compile-jsp, it don't' work. I have tried :
    <welcome-file-list>
    <welcome-file>servlet/.hdi_0005findex</welcome-file>
    </welcome-file-list>
    I don't work to.
    Have you a solution ?????????
    Thanks,
    Elisabeth
    France

    I have dowloaded the jakarta-tomcat-4.0.2-b2 (21 Jan).
    The comportement is the same as 4.0.1 !!!!!!

  • Welcome-file issue in App Server 8.2

    Hello all,
    can you explain some strange behaviour of Application Server?
    I have to set some page as a starting page. We all know that i have to put
    <welcome-file-list>
    <welcome-file>MyStartPage.jsp</welcome-file>
    </welcome-file-list>
    </web-app>
    to web.xml.
    So, my app does not include servlets, and i have web.xml as following:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <welcome-file-list>
    <welcome-file>MyStartPage.jsp</welcome-file>
    </welcome-file-list>
    </web-app>
    BUT: this works in Tomcat, but does NOT work in Sun App Server 8.2.
    In SUN App server, i have to add
    <servlet>
    <servlet-name>Fake servlet</servlet-name>
    <jsp-file>MyStartPage.jsp</jsp-file>
    </servlet>
    to web.xml (obviously, before welcome-file-list element).
    IMHO, it's an issue... Why do i have to use some fake declaration?
    Can someone test this curious issue against other App servers?
    Thanks in advance, Vad.

    Hi,
    I am facing the same issue. I did not verify with Tomcat but with an earlier version - 1.4.01
    It used to work earlier with J2ee sdk 1.4.01. I installed the J2ee sdk 1.4.03 after uninstalling 1.4.01. I had a bunch of JSPs, and a web.xml specifying the welcome page. It used to work fine. Now after 1.4.03, (server 8.2), the welcome page does not work. Instead it displays the list of JSPs on the page. There have been no modifications to the web.xml. The 8.2 has a bug here.

  • Welcome-file ignored?

    The application does not take the welcome-file specified in web.xml into account.
         <welcome-file-list>
              <welcome-file>home.jsp</welcome-file>
         </welcome-file-list>
    I tried with home.jsp, /home.jsp, home.jsf and /home.jsf, but without success.
    Direct access works well so the page is ok.
    Am I missing some part of the configuration?
    Help would be appreciated.
    Bruno
    http://www.practicalsoftwarearchitect.com

    with some containers, if the literal file doesn't exist , it won't work. Example, if I have a servlet mapped to the uri '/index.html', unless I have an index.html file at the root of my application, it won't resolve in the welcome-file-list.

  • Welcome File Trouble

    This should be an easy problem, but I've been at it for some time now... When I use the URL http://127.0.0.1:8080/myapp/, the welcome-file I specify in web.xml is
    not displayed, but a directory listing instead for the directory $tomcat/webapps/myapp.
    I can, however, type in the full name of the welcome-file (i.e. http://127.0.0.1:8080/myapp/IndexServlet) and arrive there.
    The bottom of my web.xml file is as follows:
        <welcome-file-list>
            <welcome-file>IndexServlet</welcome-file>
        </welcome-file-list>
        <resource-ref>
            <description>DB Connection</description>
            <res-ref-name>jdbc/MySQL</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>
    </web-app>I am using a Context that I defined in server.xml and I suspect that may be related. Does anyone know any
    possible causes of this?
    The Context portion of my server.xml is as follows:
                    <Context className="org.apache.catalina.core.StandardContext" cachingAllowed="true"
    charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true" crossContext="true"
    debug="3" docBase="myapp" mapperClass="org.apache.catalina.core.StandardContextMapper" path="/myapp" privileged="false" reloadable="true"
    swallowOutput="false" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper">
                        <Logger className="org.apache.catalina.logger.FileLogger" debug="0" directory="logs"
    prefix="myapp." suffix=".txt" timestamp="true" verbosity="5"/>
                        <Resource auth="Container" name="jdbc/MySQL" type="javax.sql.DataSource"/>
                        <ResourceParams name="jdbc/MySQL">
                            <parameter>
                                <name>username</name>
                                <value>*****</value>
                            </parameter>
                            <parameter>
                                <name>password</name>
                                <value>*****</value>
                            </parameter>
                            <parameter>
                                <name>driverClassName</name>
                                <value>com.mysql.jdbc.Driver</value>
                            </parameter>
                            <parameter>
                                <name>url</name>
                                <value>********************************</value>
                            </parameter>
                        </ResourceParams>
                    </Context>Thanks,
    Dave

    It's unlikely; if you're suggesting that you couldn't
    have a web application
    with only servlets, then there is no way there is a
    rule like that."No way"? Really? Well you could look at the source of Tomcat and find out. After couple of minutes of peeking I saw:
         * Check to see if a default page exists.
         * @param pathname Pathname of the file to be served
        private ResourceInfo checkWelcomeFiles(String pathname,
                                               DirContext resources) { ... }Note the "Pathname of the file to be served."
    So you could be wrong in your belief.
    /k1

  • Welcome-file to point to file in directory

    Hi,
    I'm having trouble getting my servlet to launch the correct file from startup. I have a .vm file located at:
    /WEB-INF/pages/teaser.vm
    and in my web.xml file, I put:
    <welcome-file-list>
    <welcome-file>/pages/teaser.vm</welcome-file>
    </welcome-file-list>
    This ends up showing the directory structure of my project.
    I even tried using
    <welcome-file-list>
    <welcome-file>/WEB-INF/pages/teaser.vm</welcome-file>
    </welcome-file-list>
    which just says "resource can not be found"
    But if I put teaser.vm outside the WEB-INF folder and use:
    <welcome-file-list>
    <welcome-file>teaser.vm</welcome-file>
    </welcome-file-list>
    then it shows up... I don't want to have to do this, however, since I would like to keep my directory structure as clean as possible.

    nvermind, i got it to work by placing the directory outside of the WEB-INF folder... I guess i'm too new at this stuff ^_^"'

  • Change welcome file for webapp

    Hi,
    I just installed SunOne web server 6.1 SP4, and deployed the [simple] webapp coming with the server distribution by following the steps in "Sun One Web Server 6.1 Getting Started Guide". I pointed my browser to http://my-sunone-61-server/simple, I got the index page for [simple] webapp. Easy !
    I want to see if I can change the welcome page for the webapp, so I create a login.html in the root directory for the [simple] webapp, change the welcom-file from index.html to login.html in web.xml, and restart the server. Now I expect to get the login page when I point my browser to http://my-sunone-61-server/simple, I thought this should be simple and straightforward enough. But unfortunately it is not. The login page does not show up. I still get the index page.
    Do I have to add the login.html to the admin server's index filenames list ? Or am I missing anything in my configuration? Please advice. Thx.

    If you config the web.xml as this:
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    </welcome-file-list>The <welcom-file-list/> unit must be the last unit of web.xml just like this:
    <web-app>
    <servlet-mapping>
    <servlet-name>aa</servlet-name>
    <url-pattern>/aaServlet</url-pattern>
    </servlet-mapping>
    <mime-mapping>
    <extension>doc</extension>
    <mime-type>application/msword</mime-type>
    </mime-mapping>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    </welcome-file-list></web-app>
    I don't know whether it is helpful with you.But try ! Good Luck!

  • How to chage the welcome file in web.xml using creator?

    Hi guys,
    I want to set the welcome file in web.xml to index.html but every time I run my project in creator, creator replaces index.html by faces/index.jsp. I need the index.html to check if the browser enables cookies & javascript and then I redirect to index.jsp. If I change the web.xml in a common editor, build the war-file with ant and deploy the project with tomcat, everything is fine. but how can I change it in creator?
    thanks in advance

    Sorry, that doesn't make much sense.
    The XML you gave is a configuration file for txt2xml utility. It doesn't represent the output format.
    Are you a user of this utility?

  • Invalid element 'welcome-file-list' in content of 'web-app',

    HI, folks.
    I recently used struts to develop a simple web applicaiton, and whenever I tried to use tag libs
    such as /WEB-INF/struts-html.tld
    /WEB-INF/struts-html.tld and
    tried to compile it, it gives out compile error such as:
    Error(52,21): Invalid element 'welcome-file-list' in content of 'web-app', expected elements '[taglib, resource-env-ref, resource-ref, security-constraint, login-config, security-role, env-entry, ejb-ref, ejb-local-ref]'.
    if I remove the above tag libs, the jsp file compiles
    without any problem.
    Are you guys familiar with these problems?
    please let me know if I'm doing anything foolish.
    Thanks!

    Unless some other elements tag are not close correctly this error does not make sense. Can you cut and paste your web.xml?
    It should look something like:
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <welcome-file-list>
      <welcome-file>/untitled1.jsp</welcome-file>
    </welcome-file-list>
    <taglib>
      <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
      <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
    </taglib>
    </web-app>Charles.

Maybe you are looking for

  • Framed-Ip-Address missing in Access-Request & Acct-Start messages

    We have a Cisco 7206(IOS12.2(33)) equipment associated with freeRadius server2.1.10.  Upon PPPOE client start, dynamic IP is assigned from the IP-Pool to the PPPOE client. However this IP address, is not included in the Frame-IP-Address AVP sent in t

  • Document Access

    Hi, We have a scenario where a customer would like to publish the documents which are created in Solman in the SAP NW KM. In R/3 you can use the DMS Connector for external access, but the DMS is not included in Solman. My questions are: How can you p

  • How do I reset security question answers on my account?

    How do I reset security question answers on my account?

  • Tnsnames.ora General Question

    We are experiencing a problem that many different users seem to have many different versions of tnsnames.ora. We want to create our "gold" version and ensure that everyone uses the same one. Two questions: 1. Is the "alias" that you give each connect

  • The remote device closed the connection!!! HELP

    Hi, Brought the Ms-6967 Bluetooth USB adapter so I could connect it to my nokia 7650. But have had big problems which failed in me getting anything out of the product. For starters every time I reboot my pc, I have to re-install the driver for the Bl