I m reading a very good book made by reputable authors and doing some samples in it. I came to the web.xml part, with the init-param to be specific. I have a servlet that retrieves this parameters BUT Im receiving null value. I just search in our Javaranchs with same topic. And fortunately I found one and resolve the problem by putting <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>/servlet/Test</url-pattern> </servlet-mapping> My question is, are there many different implementations of web.xml that's why the book Im reading dont include this tags? Thanks.
This is a pretty standard deal here. If your book makes no mention of this then you need a new book. You could call the servlet by it's fully qualified class name and you wouldn't need this. For example: http://<machineName>/com.whatever.servlets.TestServlet but it's hard to believ this isn't included in a book about servlets.
No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Joined: Jun 06, 2002
Supposed to be it shld work(meaning I can retrieve this parameters into my servlet) even without <servlet-mapping> tags, am I right? or the <servlet-mapping> is really necessary?
Nelson, whether you use the <servlet-mapping> element or not, you should still be able to access your servlet inital parameters. I would check your Test.java code and verify that you are accessing the ServletConfig object. There are couple of way to do this. 1)You can access SERVLET initial parameters by declaring it as part of your init method signature.
, this method is called by the container after the servlet is created or you could retreive the ServletConfig object by calling the getServletConfig() of the GenericServlet class, which you should have access too. craig