You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Woodchuck <wo...@yahoo.com> on 2004/06/28 17:57:49 UTC

web.xml pointing to other xml files?

under the <web-app> section of the web.xml file, can we arbitrarily
reference other xml files?

that is, if i put all my <servlet> tags in one file (my_servlets.xml)
and all my <servlet-mapping> tags in another file (my_mappings.xml), is
it possible to reference these from the web.xml file (and not upset
tomcat in doing so)?

also, i was experimenting and discovered i could place <servlet> tags
and <servlet-mapping> tags in different orders (within <web-app>
section) and it still works!  not that i'm complaining but i'm
surprised because when i do that, the console displays a lot of errors
when tomcat 'picks up' these changes, yet it's still able to understand
them and things seem to work fine... is this intentional by tomcat? 
ie. if breaking the DTD order does not break the application then why
do we need the DTD order?



		
__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: web.xml pointing to other xml files?

Posted by Tim Funk <fu...@joedog.org>.
I *think* you should be able to use XML entities to include other files into 
web.xml.

Tomcat does not attempt to make sure that web.xml is valid document with 
respect to the dtd. There are occasions where you can put elements in web.xml 
out of order, and things will work ok. But that doesn't mean it will work in 
future versions. (Or be portable to other containers)


-Tim

Woodchuck wrote:
> under the <web-app> section of the web.xml file, can we arbitrarily
> reference other xml files?
> 
> that is, if i put all my <servlet> tags in one file (my_servlets.xml)
> and all my <servlet-mapping> tags in another file (my_mappings.xml), is
> it possible to reference these from the web.xml file (and not upset
> tomcat in doing so)?
> 
> also, i was experimenting and discovered i could place <servlet> tags
> and <servlet-mapping> tags in different orders (within <web-app>
> section) and it still works!  not that i'm complaining but i'm
> surprised because when i do that, the console displays a lot of errors
> when tomcat 'picks up' these changes, yet it's still able to understand
> them and things seem to work fine... is this intentional by tomcat? 
> ie. if breaking the DTD order does not break the application then why
> do we need the DTD order?

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: web.xml pointing to other xml files?

Posted by Woodchuck <wo...@yahoo.com>.
hi QM,

just thought i'd follow up on how i ended up doing mine.  it's
essentially the same strategy but instead of including everything in
the jspc generated file, i'm only including the exact segment that i
need and i'm using the plain <replace> task.

build file:

<loadfile srcfile="web.xml" property="myfile">
<filterchain>
<headfilter lines="-1" skip="10"/>
<tailfilter lines="-1" skip="3"/>
</filterchain>
</loadfile>

<replace file="${webapp.build}/WEB-INF/web.xml" 
token="&lt;!-- @SERVLET_MAPPINGS@ --&gt;" 
value="${myfile}"/>


web.xml file:

<servlet>
    <servlet-name>action</servlet-name>
   
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>

  <!-- @SERVLET_MAPPINGS@ -->

  <!-- Standard Action Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

by replacing the my entire 'placeholder' string "<!--
@SERVLET_MAPPINGS@ -->" with the servlet mappings from jspc, my web.xml
file is still valid even if i never pre-compile.

thanks again for your help!  "TMTOWTDI" is really true for Ant!

woodchuck
 

--- QM <qm...@brandxdev.net> wrote:
> On Mon, Jun 28, 2004 at 09:45:55AM -0700, Woodchuck wrote:
> : actually i'm using Ant too.  i'm pre-compiling using the <jspc>
> task
> : and it generates a file containing <servlet> and <servlet-mapping>
> : tags.  that's exactly what i need to do really, is to merge this
> file
> : with my web.xml file.  if you can show me how you're doing it that
> : would be great, thanks!
> 
> Appended below.  Perl's "TMTOWTDI" motto reigns here, because I'm
> certain there are other (and gmore elegant) ways to do this...
> 
> -QM
> 
> 
> ... from build.xml ...
> 	<!--
> 	make the contents of the precompiled JSP mappings
> 	(from the "jspc" task) available as a replacement
> 	variable "@PRECOMPILED_JSPS@" in web.xml
> 	-->
> 
> 	<loadfile
> 		property="jsp.precomp.data"
> 		srcFile="${warfile.build_dir}/WEB-INF/precompiled_jsps.xml"
> 	/>
> 
> 	<!--
> 	copy the web.xml to its destination, and in the process,
> 	replace "@PRECOMPILED_JSPS@" with the content of the
> 	precompiled_jsps.xml file
> 	-->
> 
> 	<copy
> 		file="files.WEB-INF/web.xml"
> 		overwrite="true"
> 		toFile="${warfile.build_dir}/WEB-INF/web.xml"
> 	>
> 		<filterset>
> 			<filter
> 				token="PRECOMPILED_JSPS"
> 				value="${jsp.precomp.data}"
> 			/>
> 		</filterset>
> 
> 	</copy>
> 
> ... from web.xml (before it's copied with Ant's <copy> task ...
> 
> 	<!-- BEGIN: precompiled JSPs -->
> 	@PRECOMPILED_JSPS@
> 	<!-- END: precompiled JSPs -->
> 
> 
> -- 
> 
> software  -- http://www.brandxdev.net
> tech news -- http://www.RoarNetworX.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 



	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: web.xml pointing to other xml files?

Posted by QM <qm...@brandxdev.net>.
On Mon, Jun 28, 2004 at 09:45:55AM -0700, Woodchuck wrote:
: actually i'm using Ant too.  i'm pre-compiling using the <jspc> task
: and it generates a file containing <servlet> and <servlet-mapping>
: tags.  that's exactly what i need to do really, is to merge this file
: with my web.xml file.  if you can show me how you're doing it that
: would be great, thanks!

Appended below.  Perl's "TMTOWTDI" motto reigns here, because I'm
certain there are other (and gmore elegant) ways to do this...

-QM


... from build.xml ...
	<!--
	make the contents of the precompiled JSP mappings
	(from the "jspc" task) available as a replacement
	variable "@PRECOMPILED_JSPS@" in web.xml
	-->

	<loadfile
		property="jsp.precomp.data"
		srcFile="${warfile.build_dir}/WEB-INF/precompiled_jsps.xml"
	/>

	<!--
	copy the web.xml to its destination, and in the process,
	replace "@PRECOMPILED_JSPS@" with the content of the
	precompiled_jsps.xml file
	-->

	<copy
		file="files.WEB-INF/web.xml"
		overwrite="true"
		toFile="${warfile.build_dir}/WEB-INF/web.xml"
	>
		<filterset>
			<filter
				token="PRECOMPILED_JSPS"
				value="${jsp.precomp.data}"
			/>
		</filterset>

	</copy>

... from web.xml (before it's copied with Ant's <copy> task ...

	<!-- BEGIN: precompiled JSPs -->
	@PRECOMPILED_JSPS@
	<!-- END: precompiled JSPs -->


-- 

software  -- http://www.brandxdev.net
tech news -- http://www.RoarNetworX.com


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: web.xml pointing to other xml files?

Posted by Robert Koberg <ro...@koberg.com>.
Woodchuck wrote:

>
>actually i'm using Ant too.  i'm pre-compiling using the <jspc> task
>and it generates a file containing <servlet> and <servlet-mapping>
>tags.  that's exactly what i need to do really, is to merge this file
>with my web.xml file.  if you can show me how you're doing it that
>would be great, thanks!  i didn't look into doing this right away
>because i thought it would be simpler to just have web.xml point to
>this file... :p
>  
>
You could use XSL and output a file from something like:


<xsl:variable name="otherDescriptor" select="document('_web.xml')/*"/>

<xsl:template match="/">
  <xsl:apply-templates select="//filter"/>
  <xsl:apply-templates select="$otherDescriptor//filter"/>
  <xsl:apply-templates select="//filter-mapping"/>
  <xsl:apply-templates select="$otherDescriptor//filter-mapping"/>
  <xsl:apply-templates select="//servlet"/>
  <xsl:apply-templates select="$otherDescriptor//servlet"/>
  <xsl:apply-templates select="//servlet-mapping"/>
  <xsl:apply-templates select="$otherDescriptor//servlet-mapping"/>
</xsl:template>

best,
-Rob

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: web.xml pointing to other xml files?

Posted by Woodchuck <wo...@yahoo.com>.
--- QM <qm...@brandxdev.net> wrote:
> On Mon, Jun 28, 2004 at 08:57:49AM -0700, Woodchuck wrote:
> : under the <web-app> section of the web.xml file, can we arbitrarily
> : reference other xml files?
> : that is, if i put all my <servlet> tags in one file
> (my_servlets.xml)
> : and all my <servlet-mapping> tags in another file
> (my_mappings.xml), is
> : it possible to reference these from the web.xml file (and not upset
> : tomcat in doing so)?
> 
> Yes and no: you can call external entity references (which, in turn,
> point to files) from your web.xml; but as there is no guarantee of
> what
> is a webapp's "current directory" you'd have to hardcode those paths.
> That would make your app less portable between containers and perhaps
> even different Tomcat revs.
> 
> You could merge your files of <servlet> and <servlet-mapping> tags at
> build time. For example, I use the Ant tasks <loadfile> and <copy> +
> <filter>.  If you're interested, I'll post that in detail.

actually i'm using Ant too.  i'm pre-compiling using the <jspc> task
and it generates a file containing <servlet> and <servlet-mapping>
tags.  that's exactly what i need to do really, is to merge this file
with my web.xml file.  if you can show me how you're doing it that
would be great, thanks!  i didn't look into doing this right away
because i thought it would be simpler to just have web.xml point to
this file... :p

> 
> 
> : also, i was experimenting and discovered i could place <servlet>
> tags
> : and <servlet-mapping> tags in different orders (within <web-app>
> : section) and it still works!
> 
> What servlet spec do you specify in your web.xml?
> IIRC 2.4's schema permits a more logical order, such as 
> 
> 	<servlet>
> 	<servlet-mapping>
> 	<servlet>
> 	<servlet-mapping>
> 
> -but don't quote me on that, as I don't have the spec in front of me
> right now.

my web.xml header is this:

<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

i didn't alternate <servlet> and <servlet-mapping> though.  i kept the
'group' integrity so all the <servlet> tags were together first, then
came all the <servlet-mapping> tags.  what i did mix up though, was
putting this chunk in various places within the <web-app> tag.  for
example i put this chunk as the very last 'section' before </web-app>,
then i tried putting this chunk right in-between two <taglib>
definitions.  in both cases, when tomcat 'picked up' these changes it
caused various parsing-related errors on the console, however my
application still worked *seemingly* without any problems.




	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: web.xml pointing to other xml files?

Posted by QM <qm...@brandxdev.net>.
On Mon, Jun 28, 2004 at 08:57:49AM -0700, Woodchuck wrote:
: under the <web-app> section of the web.xml file, can we arbitrarily
: reference other xml files?
: that is, if i put all my <servlet> tags in one file (my_servlets.xml)
: and all my <servlet-mapping> tags in another file (my_mappings.xml), is
: it possible to reference these from the web.xml file (and not upset
: tomcat in doing so)?

Yes and no: you can call external entity references (which, in turn,
point to files) from your web.xml; but as there is no guarantee of what
is a webapp's "current directory" you'd have to hardcode those paths.
That would make your app less portable between containers and perhaps
even different Tomcat revs.

You could merge your files of <servlet> and <servlet-mapping> tags at
build time. For example, I use the Ant tasks <loadfile> and <copy> +
<filter>.  If you're interested, I'll post that in detail.


: also, i was experimenting and discovered i could place <servlet> tags
: and <servlet-mapping> tags in different orders (within <web-app>
: section) and it still works!

What servlet spec do you specify in your web.xml?
IIRC 2.4's schema permits a more logical order, such as 

	<servlet>
	<servlet-mapping>
	<servlet>
	<servlet-mapping>

-but don't quote me on that, as I don't have the spec in front of me
right now.

-QM

-- 

software  -- http://www.brandxdev.net
tech news -- http://www.RoarNetworX.com


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org