I need to send a XML file from a servlet to another one as a servlet response or through Headers.
I found the few methods to achieve this 1) Sending the XML file object in the Servlet Output Stram 2) Opening the second servlet using URL connection and then add these details 3) Sending the file as an Http Header attachment. In the second option I have a sample program like this
Welcome to JavaRanch. I wanted to let you know that we have a cool feature that would make your code more readable for posts.
Under the Add Reply button (when adding a post) there are 10 buttons, one of them is labeled "code" this will create CODE tags in your post, if you paste your code inside these tags, then the code in the thread will keep all your formatting, including indentations which make code easier to read.
There are also buttons for quoting, adding a link to a URL, a link to an EMAIL address, and a couple more cool ones.
I haven't read your code (due to formatting and length) and I don't understand why you need to pass the XML file between servlets but, if the servlets are part of the same app and/or session, why not just hold a reference to the object containing the XML file in the app or session context?
Hello Saravanan, I'm fairly new to this whole servlet thing myself but I've been able to get XML data back and forth between servlets on different machines. Without knowing what you are talking to, which could be a problem service in itself, it looks like you never call "connect" on your URLConnection.
Here is some code that seems to work for me, again, please take it with a grain of salt...
I use HTTPURLConnection which is a subclass of the one you use but should do what you want. After you have called connect you can then get your input and output streams.