wood burning stoves*
The moose likes Servlets and the fly likes servlet-mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet-mapping" Watch "servlet-mapping" New topic
Author

servlet-mapping

Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 169
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.
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
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?
Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 169
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?
Neeraj Singhal
Ranch Hand

Joined: Aug 13, 2000
Posts: 49
Nelson
It is not required to have <servlet-mapping tag>.
It works without it.
Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 169
Then there must be something wrong with web.xml of JRun? because its not working... I needed the url-mapping tags to work this...
or I need to edit the part of web.xml
Thanks fellow Java ranchers....
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
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
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Hi Nelson
<servlet-mapping> tag should not be inside <servlet> tag. It should be like this:

I am not sure this is causing the problem.
-Sainudheen
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Parameters passed to a servlet are indeed defined in the deployment descriptor file in the <init-param> element.
You retrieve parameters by using methods declared in the ServletConfig interface:
public interface javax.servlet.ServletConfig {
public String getInitParameter(String name);
public java.util.Enumeration getInitParameterNames();
}
You can get the ServletConfig like this:
javax.servlet.ServletConfig {
public ServletContext getServletContext()
}

javax.servlet.ServletContext {
public ServletContext getContext(java.lang.String uripath)
}

javax.servlet.HttpSession {
public ServletContext getContext()
}


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 169
Whew, that's really a lot of tips to look on. I really appreciate you all. Thanks again.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: servlet-mapping
 
Similar Threads
Configuring a jsp page in web.xml
question for url-pattern
Doubt about how configuring init parameters in JSP
Servlet path stupid question
Servlet Mapping problem - please help