Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

servlet-mapping

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whew, that's really a lot of tips to look on. I really appreciate you all. Thanks again.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic