This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

welcome-file-list... A BUG?  RSS feed

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I can't understand why the welcome-file-list doesn't work.
web.xml (case 1 - IT DOES NOT WORK)
-------
When I try to access http://localhost, the
`Login` servlet is called. WHY??
-------
<!-- ... -->
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>abc.Login</servlet-class>
</servlet>
<servlet>
<servlet-name>Index</servlet-name>
<jsp-file>/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>Index</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- ... -->

web.xml (case 2 - IT WORKS FINE)
-------
The difference is the order of two
<servlet-mapping>
-------
<!-- ... -->
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>abc.Login</servlet-class>
</servlet>
<servlet>
<servlet-name>Index</servlet-name>
<jsp-file>/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Index</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- ... -->
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to use servlet mappings here? Servlet mappings only need to be used if you plan on mapping a URL extension to a mapping. For example, the Struts framework recognizes *.do as a servlet mapping so that all URLs that end with *.do filter through their servlet.
If you just want your app to default to index.jsp, your welcome-file-list alone should be enough to do the job.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for "why" does it happen?

You are mapping two different resources to the exact same URI ( '/' )

By demonstration, you've shown us that Tomcat resolves the impossible dilemma of two mappins for the same URI by ignoring every mapping except the last one it processes.

So in your first version, it calls the login servlet, because that's the last mapping, and in the second case it gets index.jsp. It *doesn't* get it from the welcome-file listing. By asking for / you are asking for a well-defined page (via your mappings). Welcome-list is used when the container doesn't know what to use.

p.s. Mapping *.jsp is unnecesary for just about every servlet container around.
 
All of the following truths are shameless lies. But what about this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!