• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

init-param issues

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off, Tomcat/5.5.9 with Servlet 2.4 and JSP 2.0

ok, been fighting with the init() method for a while now, search through a few forums, 3 different books, api, faqs, and I have yet to get it working. The problem is none of my <init-param> are being read. I have written the init() a dozen different ways, re-wrote my web.xml twice, and no change in my page. Right now my init() method is like this


I have tryed both init() and init(ServletConfig config), no change, tryed with and without the call to super.init() tryed getting one param, all, a few, getting parameter names, not getting parameter names, a few other things that give funny errors, and all parameters still end up being null as does the getInitParameterNames().

My current web.xml is below, its changed a few times, but as far as I can see, its correct.



At the moment, Im a loss of what to do next. Im sure after a few posts it will end up being something stupid easy that I should have seen some time ago, but I really don't know whats wrong.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see a servlet mapping in your web.xml. Just how are you invoking the servlet?
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do I see a web_app there? It should be web-app
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And...

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And yes, as Bear pointed out, please provide the servlet-mapping tag. But if it is not a typo, it must be web-app and not web_app. I guess that is the problem.
 
will phillips
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It lacks the servlet mapping because the example I was working out of does not use any, but seems like I will be changing that shortly. As for the "_"...I made the incorrect assumption that the web.xml I copied out of (I didn't want to write the first three lines again) was correct to begin with....figured it would be something stupid like a semi-colon or similar. I�m sure I wouldn't have had to post if I wasn't working on a term paper, an ERP assessment assignment, and a surprisingly large program in something I am more familiar with....

As for the name, it has been updated, I was even told by my teacher that I would have to use a proper name, sorry about that.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have example apps for both context init params and for servlet init params at http://simple.souther.us. Sometimes a working example is worth a thousand words.

PS:
They also demonstrate the proper use of a servlet mapping.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sure you know this. But, you have to access the servlet by it's name. In your case your servlet class and name are the same (Not always the best idea). Since, you do not have any URL mapping, one really has to see how you are accessing the servlet.
 
will phillips
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im new to JSP and Servlets, so Im following a book alot, in this case the example accessed the Servlet with http://localhost:8080/example/servlet/Message and the web.xml lacked the servlet mapping. So what I was doing lacked it aswell and I accessed via the same url. If I wasn't teaching the majority of this to myself, and taught by a teacher that has been teaching the class for longer (new teacher, not perfect) I would be following the standards more.

I am working on the servlet mapping, amoung other coding practices.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://localhost:8080/example/servlet/Message
That url suggests that your book is a little out of date.

With current app servers, you need to explicitly map your servlets to a url pattern.

See: http://faq.javaranch.com/view?InvokerServlet
for all the details.
 
will phillips
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Book I am using is "Core Web Programming 2nd Edition" example is in chapter 19 on page 891-892 if you don't have the book, the code is linked below.

(C)2001 so I really didn't think it was that old, but at anyrate, I will be using the mapping.

ShowMessage.java
web.xml
 
Not so fast naughty spawn! I want you to know about
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic