• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet mapping and taglib mapping

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found servlet mapping and uri mapping for .tld file (sections 5.2.3, 5.2.4 and
15.2.1 to 15.2.4 of SCWCD exam study kit) to be most confusing.
Given that the sub elements <servlet> and <servlet-mapping> of
<web-app> element are optional, (see the definition of <web-app> element given on page 87), what if I write
a servlet for my web application, but do not declare it in web.xml ? Can this servlet still accessible using
exact servlet name ?
On page 72, it says that the us-sales servlet can be accessed through the URL,
http://www.myserver.com/servlet/us-sales. Why /servlet is necessary ? In fact,
isn't context path i.e web application name missing in this ?
On page 77, how servlet path /red match /red/*, if /blue does not match /blue/ ?
On page 284, table 15.1, it says that we can use absolute URI for uri attribute in taglib directive
e.g. http://www.manning.com/taglibs. But, on page 289, it says 'If the specified uri attribute is an
absolute URI, then it is an error and is reported at translation time.'
Any thoughts on above points ?
thanks
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. We need not declare all servlets of a web application under web.xml. We can always access it through the standard way.
http://server ort/servlet_context_name/servlet/FullyQualifiedServletClassName
Example :
1. http://localhost:8080/myApp/servlet/HelloServlet
2.http://localhost/myApp/servlet/com.canopy.HelloServlet
2.Regarding your page 72 question, I assume the web application is mapped to default application. There are container specific ways to map a web app to default app. So in this case the servletContext name is just ""
If you have Tomcat installed check on conf\server.xml for these lines which does this kind of mapping.
<!-- Tomcat Root Context -->
<Context path="" docBase="ROOT" debug="0"/>

3. Reg. page 77 question, /blue/ does not have a * after the slash , meaning we have to have the exact uri mapping of /blue/. On the other hand /red/* means either /red or /red/ or /red/test will be mapped right.
4. The uri attribute <%@ taglib .... /> directive can in fact have absolute / root relative / non-root relative URIs.
But the important point is if this attribute is assigned with an absolute URI then it MUST have a mapping in web.xml like below.
<taglib>
<taglib-uri> absoluteURI here </taglib-uri>
<taglib-location> some val </taglib-location>
</taglib>
If there is no mapping found, then only we will get an error.
Please read that section more closely. The section is written as an if ..... else if .... way/ Notice the tabbed format of the bulleted points.
Regards,
Maha Anna
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Maha Annadurai:
1. We need not declare all servlets of a web application under web.xml. We can always access it through the standard way.
http://server ort/servlet_context_name/servlet/FullyQualifiedServletClassName


I quite often saw this kind of suggestions (some said "/servlet/..", and some said "/servlets/...") in accessing a servlet. However, I could not find anywhere in the Servlet Spec mentioned that this is legal.
Is it just another free offer provided by Tomcat?
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/servlet/servletName is the right standard method to invoke a servlet in any server. There is no 's' after 'servlet'.
It all started way back with JSDK. (Java Servlet Development Kit- the very first sdk released for servlet development from Sun) It is unfortunate that the current Servlet spec does not say anything about this concept.
Here is a link to the old reference documentation I got hold of which explains the standard way to invoke a servlet.
http://www.urz.uni-heidelberg.de/UnixCluster/Hinweise/Hilfe/Anwendung/Compiler/JSDK2.0/README
Regards,
Maha Anna
[ December 12, 2002: Message edited by: Maha Annadurai ]
 
k space
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I skimmed through that JSDK document very quickly. It was a development kit and only addressed servlet (did not have the whole Web Application concept). Yes, it mentioned that "/servlet/<servlet-name>/..." was a standard way to invoke a servlet in any server.
With the new servlet spec, all deployment settings should be defined inside web.xml including servlet-mapping.
I am using WebLogic 7 to test my code. If I don't specify a servlet-mapping to map an URL to my servlet. I get "Error 404--Not Found".
One more thing, the exam is testing us about JSP 1.2 and Servlet 2.3.
 
Rasika Chitnis
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to get this straight, is /servlet a standard way to access a servlet ? should it work for any servlet container and for any web application i.e. default or non-default and regardless of the fact that the servlet has any mapping in web.xml or not ?
thanks
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ks wong,
I was under the impression all servlet/jsp containers are expected to support the /servlet/ way of invoking servlets.
But I agree that it definitly leaves a security hole for any one who can guess the name of the servlet can execute it.
Can you tell us the Servlet 2.3 spec section where it is specified ?
Thanks!
Regards,
Maha Anna
[ December 13, 2002: Message edited by: maha anna ]
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My understanding is that a servlet container only uses url mapping to find a servlet. In the case of Tomcat, we can access a servlet using "/servlet/..." only when the following element in web.xml:

<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

In this case, Tomcat first invokes the invoke servlet, then it's up to this servlet to the job.
 
k space
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by maha anna:
Can you tell us the Servlet 2.3 spec section where it is specified ?


So far I learnt from the spec, the only way is to use <servlet-mapping> to map an URL-pattern to a servlet (one servlet only).
With Yi Zhu's suggestion, both /servlet/MyServlet1 and /servlet/MyServlet2 are handled by invoker servlet. Of course, invoker can further forward the request to either MyServlet1 or MyServlet2 based on the path info. But what's the point of doing our own mapping?
Why not simply use the built-in servlet-mapping capability to achieve the job. It's a standard, everyone understands how it works (?), and declarative.
reply
    Bookmark Topic Watch Topic
  • New Topic