File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes can web.xml data include contents from other xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "can web.xml data include contents from other xml file" Watch "can web.xml data include contents from other xml file" New topic
Author

can web.xml data include contents from other xml file

Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83
Hello,

In a web application, can the web.xml dd load configuration from other xml files speciefied in WEB-INF folder.



SCJP 1.5, SCWCD 1.4.
Hanging between Web Services and EJB
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9307
    
  17

I don't think that this kind of thing can be done...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
stef li
Greenhorn

Joined: Jan 16, 2006
Posts: 27


This guy is so lazy!!!<br />There is nothing left!
Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
Yes, using context-param
Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83
hi thanks for the reply.

what does this exactly mean

stef li
Greenhorn

Joined: Jan 16, 2006
Posts: 27
it means that there are serial config files under the classpath of the project.
the file name is begin with "applicationContext"

Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
here's an example:
<param-value>/WEB-INF/theXmlThatContainsSomeConfiguration.xml</param-value>

it's the path to your xml file that you want to load
Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83

Please tell whether the following configuration is right?

web.xml File:




applicationContextTest.xml File:




I am getting resource not found error when i access the servlet directly.

Ashwin Pai
Ranch Hand

Joined: May 20, 2008
Posts: 90
Ramkumar Subburaj wrote:Hello,

In a web application, can the web.xml dd load configuration from other xml files speciefied in WEB-INF folder.



Why would you want to do this ? I see in a subsequent post that you are trying to use a xml file that has the servlet mapping in web.xml
What is the requirement that drives you to do this ?

Ashwin


The only way to make your dream come true is to wake up.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

A context param does not cause any files to automatically be "included" in the web.xml.

What are you really trying to accomplish?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83
we are 3 in the team and working in one project. We find it difficult to maintain the web.xml when clubbing all our modules. so i was thinkig if there was a way to load external xml file, we could use 3 individual xml files during development and while deploying
we can put everything into web.xml

This might(should) sound silly

is there any other better option.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42367
    
  64
The web.xml file should't be something that changes very frequently. Are you maybe keeping configuration parameters in it that would better be kept in a configuration file (like a properties file)?


Ping & DNS - my free Android networking tools app
Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
Ramkumar Subburaj wrote:
Please tell whether the following configuration is right?

web.xml File:




applicationContextTest.xml File:




I am getting resource not found error when i access the servlet directly.



Of course, because this is incorrect:
<param-value>classpath*:applicationContext*.xml</param-value>
if you have applicationContextTest in application/config/, for example, you put <param-value>config/applicationContextText.xml<param-value/>
Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83
Nick,

what does this mean

if you have applicationContextTest in application/config/

i believe application/config/ is a path and what does this point to
Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
Where you put the other xml files that you want web.xml to load. I usually keep them in a config folder in the application along with other xml and properties files, but you can put them in any folder in your application. So the param-value should point to their location.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
To clear things out, using context-param doesn't load the specified xml file automagically into the web.xml or so. It only make the name available as ServletContext#getInitParameter() so that one could use this information to load the xml file programmatically or so. I have no idea what Nick is thinking or (mis)understanding, but this is really not what you're looking for.

To solve your problem, just use a good CVS.
Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
I usually put all my servlets in a servlet.xml instead of web.xml, so when the application is loaded it reads the servlet.xml file. I do this using param-values. I assume he wants to do something similar? If i'm doing something wrong (or misunderstand something), what is that?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42367
    
  64
Bauke Scholtz wrote:using context-param doesn't load the specified xml file automagically into the web.xml

Not in a standard servlet container, but the Spring framework can be configured to work this way. That may be what's being talked about here.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Nick,
This is creating a lot of confusion.
Did you write a custom clasloader that reads the external xml files and loads the servlet classes?

If not, what container are you using?
There is nothing in the servlet spec that allows external xml files to be automatically loaded.
If your container is doing this then it is probably non spec feature provided by that container.

To avoid this type of confusion we try to keep the conversation here to features provided by the servlet specification so the answers given will work for people using any spec compliant container. If you want to discuss a container specific feature, please let everyone know what container you're using and that your answer applies only to that container.

Thanks,
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
I'm using spring, yes, sorry if it led to confusion. I've never done a web application without spring.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Thanks for clarifying this, Nick.

I was busy searching the servlet 2.5 spec to make sure I didn't miss something new.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

When someone posts here without explicitly mentioning that they are using spring (or struts, or whatever) please do not assume that they are. It just sows confusion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can web.xml data include contents from other xml file