Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet-mapping

 
Nelson Nadal
Ranch Hand
Posts: 170
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 364
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nelson Nadal
Ranch Hand
Posts: 170
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nelson
It is not required to have <servlet-mapping tag>.
It works without it.
 
Nelson Nadal
Ranch Hand
Posts: 170
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 405
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
}
 
Nelson Nadal
Ranch Hand
Posts: 170
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whew, that's really a lot of tips to look on. I really appreciate you all. Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic