Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Mapping problems

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I trying to do an web app, and I'm having problems with the servlet mapping settings.

I that when the user hits http://localhost:8080/myapp/
it goes do the servlet I mapped, and it will redirect to a jsp file.

So I did:

<servlet>
<servlet-name>Serv1</servlet-name>
<servlet-class>com.myapp.MyIndexServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Serv1</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

it seems to work fine,

but is this the right way to map the first page to and servlet? could I do with a <welcome-file>

And if I have other servlets, and put other mapping, will they be affected by this patter?

thanks
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no harm in the you choose to do the mapping. Similar behavior can be achieved by setting welcome file as well. When you configure more servlets they won't impact the existing ones as every servlet is required to have a unique URL pattern. Two servlets can not have same URL pattern though one servlet can serve many URL patterns.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And the closest URL pattern will win.
 
Mike Phillip
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks guys, really helpful
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic