Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can web.xml data include contents from other xml file

 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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

 
Ankit Garg
Sheriff
Posts: 9520
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that this kind of thing can be done...
 
stef li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Nick Potter
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, using context-param
 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks for the reply.

what does this exactly mean

 
stef li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A context param does not cause any files to automatically be "included" in the web.xml.

What are you really trying to accomplish?

 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
Nick Potter
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nick Potter
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using spring, yes, sorry if it led to confusion. I've never done a web application without spring.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic