File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes init-param issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "init-param issues" Watch "init-param issues" New topic
Author

init-param issues

will phillips
Greenhorn

Joined: Oct 10, 2005
Posts: 11
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

I don't see a servlet mapping in your web.xml. Just how are you invoking the servlet?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sravan Kumar
Ranch Hand

Joined: Sep 11, 2005
Posts: 121
Do I see a web_app there? It should be web-app


keep smilin :: sravan<br /><a href="http://sravanpens.blogspot.com" target="_blank" rel="nofollow">I scribble here</a>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

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

Joined: Sep 11, 2005
Posts: 121
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

Joined: Oct 10, 2005
Posts: 11
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.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
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.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
will phillips
Greenhorn

Joined: Oct 10, 2005
Posts: 11
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Oct 10, 2005
Posts: 11
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
 
 
subject: init-param issues
 
Similar Threads
need Help in getInitParameter()
ServletContext InitParameter Problem
Servlet can't find intialisation paramters
getInitParameter(String str)?
environment variable referance in Web.xml