Win a copy of Spark in Action this week in the Open Source Projects 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problem with web.xml file for Tomcat

 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this should be here or in the XML forum, so feel free to move it if need be.
I just loaded Tomcat today, gotten a couple of servlets to run just fine. However, I added some params to web.xml, to play with getting ServletConfig params. When I use the modified xml file, I can't even get localhost:8080 to pull up, get the 404 error. If I use the old xml file, things work fine. Here's the modified xml file

If you've read Core Servlets and JSP, then you should recognize this, it's pulled directly from the book, which is why I'm confused as to why this problem is occuring. Never done any xml stuff, so I have no idea where to begin.
Jason
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try re-starting the server?
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Several times. I change to the old xml file, restart, things work great. I change to the modified web.xml, restart, get 404 errors for everything.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is you can't have more than one name-value pair in <init-param>

From the DTD for web-app

<!--
The init-param element contains a name/value pair as an
initialization param of the servlet
Used in: filter, servlet
-->
<!ELEMENT init-param (param-name, param-value, description?)>

If you could have more than one mapping, there would be *'s beside param-name and param-value, but that wouldn't really make sense. How would you know which value went with which name?

So what you need is:
[ January 11, 2002: Message edited by: Mike Curwen ]
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I must have overlooked that in their example, thanks Mike!!
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent, works like a charm, thanks again!
Jason
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having this problem and tried a lot of thing already, my web.xml file looks like this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/dtd/web-app_2_2.dtd">;
<web-app>
<servlet>
<servlet-name>ShowMsg</servlet-name>
<servlet-class>coreservlets.ShowMessage</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>ahahahaha</param-value>
</init-param>
<init-param>
<param-name>repeats</param-name>
<param-value>5</param-value>
</init-param>
</servlet>

</web-app>
And it still doesn't work. Can anyone help?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"doesn't work" is not quite enough information to go on - there are so many things that can go wrong with a servlet, we need more clues.
1. How are you trying to address the servlet?
2. What happens next?
3. Do the Tomcat logs show any clues?
4. Does your servlet init() method do a
System.out.println("some message")
to verify that the servlet is even being called?
Bill
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic