• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with Deployment Descriptor

 
Jaggi Kunal
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the Wrox SCWCD book. In the 6th chapter the authors have given an example to demonstrate Secure Servlets. According to the book the below mentioned code should be inserted in the deployment descriptor (web.xml).
<servlet>
<servlet-name>Secure</servlet-name>
<servlet-class>SecureServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Secure</servlet-name>
<url-pattern>SecureServlet</url-pattern>
</servlet-mapping>

<security-constraint>
<web-resource-collection>
<web-resource-name>SecureResource</web-resource-name>
<url-pattern>SecureServlet/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>

<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Secure Realm</realm-name>
</login-config>

I have inserted the code in install_dir/webapps/ROOT/WEB-INF/web.xml file .
If I am not wrong this is what is called the deployment descriptor. But now when I start the server, it throws an exception and the screen is cluttered with a large stack trace. But when I comment the above made changes it works fine. What could be the problem? How do I write Secure Servlets by making use of the Deployment Descriptor. I will be obliged if anybody can help me.
Regards,
Kunal Jaggi
SCJP2
 
Kevin Mukhar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on your description of the symptoms, my first suggestion would be to ensure that the order of elements in the deployment descriptor is correct. The container is sensitive to the order of elements in the deployment descriptor. My experience has been that if any element is out of place, the container throws an exception, which is the symptom you describe. As soon as you remove the elements, the deployment descriptor is again in the correct order, so then it works.
The order of elements you show in your message is correct, however, they must also be correct in relation to the other elements in the deployment descriptor. Check here to see the order of elements shown in tree form.
Another technique to narrow down the problem is to add each element one by one, restarting each time, until you find the specific element that is causing the problem. Then you need to check that element carefully for the correct syntax, required subelements, etc.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic