About Question enthuware.jwpv6.2.842 :

Moderator: admin

Post Reply
ETS User

About Question enthuware.jwpv6.2.842 :

Post by ETS User »

I have tried this code with Tomcat 7. My web.xml looks like this

Code: Select all

  <servlet>
    <servlet-name>BookServlet</servlet-name>
    <servlet-class>com.bookServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>BookServlet</servlet-name>
    <url-pattern>*</url-pattern>
  </servlet-mapping>
for combinations like * or *.* I get a 404 on any servlet.
and the container startup fails!

Code: Select all

Feb 23, 2013 6:48:47 PM org.apache.catalina.startup.Catalina start
SEVERE: Catalina.start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:684)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 11 more

for anything like books.* it works

Guest

Re: About Question enthuware.jwpv6.2.842 :

Post by Guest »

Additionally for books.* I get an suspicios URL Pattern as shown below

Code: Select all

INFO: Suspicious url pattern: "/books.*" in context [/svrlet3] - see section SRV.11.2 of the Servlet specification
Feb 23, 2013 6:53:14 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Feb 23, 2013 6:53:14 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Feb 23, 2013 6:53:14 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1759 ms

Guest

Re: About Question enthuware.jwpv6.2.842 :

Post by Guest »

Finally only the following works

Code: Select all

  <servlet>
    <servlet-name>BookServlet</servlet-name>
    <servlet-class>com.bookServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>BookServlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
however the following code

Code: Select all

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html");

		out.println(this.getServletContext().getContextPath() + "<br />");
		out.println(request.getPathInfo() + "<br />");
		out.println(request.getServletPath() + "<br />");
only yields

/svrlet3
/show/books.do
--empty for ServletPath--

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.842 :

Post by admin »

Which version of the specification are you reading. Section 11.2 of Servlet 3.0 doesn't contain anything relevant to this.

As per section 12.2 of Servlet 3.0 specification
■ A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for
path mapping.
■ A string beginning with a ‘*.’ prefix is used as an extension mapping.
■ The empty string ("") is a special URL pattern that exactly maps to the
application's context root, i.e., requests of the form http://host:port/<contextroot>/.
In this case the path info is ’/’ and the servlet path and context path is
empty string (““).
■ A string containing only the ’/’ character indicates the "default" servlet of the
application. In this case the servlet path is the request URI minus the context path
and the path info is null.
■ All other strings are used for exact matches only.
It doesn't say anywhere that *.* or * is invalid. So it should work as explained.

Guest

Re: About Question enthuware.jwpv6.2.842 :

Post by Guest »

The problem is that is does not work as per the spec.
The whole question arose out of the contextPath, ServletPath DnD question on the Enthuware exam. The problem with Tomcat is also,
When * is used on the DD request.getServletPath() has an empty value and request.getPathInfo() returns the correct path.

When proper path is used in the DD, request.getServletPath() has a valid value and request.getPathInfo() has an empty value.

This is also documented on several places on stackoverflow.

Not saying there is anything wrong with the exam, but it seems Tomcat has not implemented the spec correctly then!

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests