Discussions

XML & Web services: Updating web.xml at runtime.

  1. Updating web.xml at runtime. (1 messages)

    Hi all,
    I'm writing a program that updates the web.xml file
    for a web application. For example I'd like to add at runtime a <taglib>
    directive so that the file changes from this:

    <!-- original web.xml -->

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <web-app>

        <servlet>
            <servlet-name>Servlet1</servlet-name>
            <servlet-class>Servlet1</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>Servlet1</servlet-name>
            <url-pattern>/testServlet</url-pattern>
        </servlet-mapping>


    </web-app>



    To this:

    <!-- updated web.xml -->


    <?xml version="1.0" encoding="ISO-8859-1"?>


    <web-app>

        <servlet>
            <servlet-name>Servlet1</servlet-name>
            <servlet-class>Servlet1</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>Servlet1</servlet-name>
            <url-pattern>/testServlet</url-pattern>
        </servlet-mapping>

    <taglib>
            <taglib-uri>
                http://www.mycompany.com/taglib
            </taglib-uri>
            <taglib-location>
               /WEB-INF/taglib.tld
            </taglib-location>
        </taglib>

    </web-app>

    I've found a simple example that updates an XML document
    (http://forum.java.sun.com/thread.jsp?forum=34&thread=168004)
    but I'm having problems in adding the <taglib> tag with nested
    elements inside.
    Please XML guru give me a clue!
    Thanks
    Francesco
  2. Well - XML isn't that hard. Just go to a bookstore and you will find everything.

    A warning: Don't change your web.xml using a J2EE application component (jsp,servlet ..).

    Although you might know for the server you are using the physical location of the deployed file (ear or war, archive or exploded) this may be (and will be) completly different for any other J2EE Server or even clustered environments. Most of the application servers on the market support hot (re-)deploy and sometimes offer management tools to update deployment descriptors during runtime. Use it instead of altering your web.xml directly.

    Jens