Web.xml Deployment Descriptor
Wall Script
Follow Me:
Tuesday, September 23, 2008

Web.xml Deployment Descriptor

Web.xml mapping servlet names improve web app's flexibility and security..The deployment descriptor (DD), provides a "declarative" mechanism for customizing your web applications without touching source code!

Tomcat Directory Structure

Login.java


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Login extends HttpServlet{

public void doGet(HttpServletRequest request,
HttpServletResponse response)throws IOException{

PrintWriter out=response.getWriter();
java.util.Date tody=new java.util.Date();
out.println("out put html tags");

}
}


<servlet>Maps internal name to fully-qualified class name.


<servlet-mapping>Maps internal name to public URL name.

web.xml



<servlet-mapping> which servlet should i invoke for this requested URL?


<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd" version="2.4">

<servlet>
<servlet-name>Servlet_login</servlet-name>
<servlet-class>Login</servlet-class>
</servlet>

<servlet>
<servlet-name>Servlet_inbox</servlet-name>
<servlet-class>inbox</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>Servlet_login</servlet-name>
<url-pattern>/signin.do</usr-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Servlet_inbox</servlet-name>
<url-pattern>/view.do</usr-pattern>
</servlet-mapping>

</web-app>


signin.do file mapping to Login.class. So the client or users to get to the servlet.. but it's a made-up name that is NOT the name of the actual servlet class.
Was this article helpful?
Thanks! Your feedback helps us to improve 9lessons.info


3 comments:

  1. hey srinivas,
    I appreciate your efforts in writing this article. but you have to write a lot of description around what you are talking about. Your pictures are good, but they do not explain much. Use more words
    -
    sridhar,
    nodalo.com

    ReplyDelete
  2. Considering all the articles available on the web and in books to explain web.xml, this isn't showing any more than the first few pages would inform the user of.

    In addition, most .do extensions tend to be struts(1) apps where there is a filter decalred in web.xml that will pass all .do url requests to struts to load up the relevant action class. If you were to code web.xml mappings as you have done then you would come a cropper when introducing struts for example, so it may be best to stay off the .do mapping to standalone servlets.

    ReplyDelete
  3. I personally liked the images & illustrations. Nothing to complain.

    ReplyDelete

Make in India