How to write XML to file from an EJB or other JEE method?

We should not be doing this from the EJB to write the data to files, however you should consider other alternatives. As transactions should not get congested.

Up vote -2 down vote favorite share g+ share fb share tw.

I'm trying to create an RSS file for access online. I already have a dynamic web project running with a servlet and several EJB's for business logic. All I want to add now is a way to create the RSS file.

I haven't found good examples online. And I'd like to write it myself anyway. Does anyone know of a way to write to an existing web file that's in the WebContent folder?

I have created a "status. Rss" file in the WebContent folder containing preloaded xml. I have accessed it through a browser.

Now I just need to reference it in my EJB and modify the content. I'm not sure how to reference the file and the methods to call to write text/xml to it. Do you use XMLstreamwriter, print statements, etc. Thank you, java java-ee servlets ejb-3.0 link|improve this question edited Nov 8 '11 at 0:03BalusC262k26271481 asked Nov 7 '11 at 18:18Randnum2628 98% accept rate.

We should not be doing this from the EJB to write the data to files, however you should consider other alternatives. As transactions should not get congested. If your model data to xml is simple , this xml api will help you to achieve that to output XML.

Also you can implement this via a servlet to pull the data. xstream.codehaus.org/ On why you should not create file from the EJB tier, please see this design document. Java blue prints on EJB tier/container restrictions.

java.sun.com/blueprints/qanda/ejb_tier/r....

Thank you. I'm new to JEE I thought all business logic including building and writing an RSS file should be contained within the Controler/EJB of an MVC framework. Are you suggesting that this should be done from the servlet instead?

Thank you – Randnum Nov 7 '11 at 18:39 1 Your inserts/updates/deletes are done through the ejb. All I am saying is that during the transaction operation, there is no neccessity to open/write files. When an RSS file is requested you can create the rss file on the fly.

Please also see servlets with custom extension and conten-type to output xml. – r0ast3d Nov 7 '11 at 18:42 My web project already has a servlet that I use to handle httprequests. But the servlet would grow rather large if I started programming XML formatting and other logic inside of the servlet.

Correct me if I'm wrong but I think it's best to do that inside of a EJB and just call that bean from the servlet. I will check out the suggestions that you made. – Randnum Nov 7 '11 at 19:52 You can have multiple servlets.

I also edited the answer to add more information on design. Technically it is possible, but one should not. – r0ast3d Nov 7 '11 at 20:34.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions