Anyone know JSP?

SP33Demon

Lifer
Jun 22, 2001
27,928
143
106
I am trying to write out an xml file and populate it through JSP. It would be greatly appreciated if anyone could help. :)
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
There's folks where wut knows some jsp but you're gonna have to describe what you're trying to do a little better.
 

SP33Demon

Lifer
Jun 22, 2001
27,928
143
106
Originally posted by: kamper
There's folks where wut knows some jsp but you're gonna have to describe what you're trying to do a little better.

Well, I've been messing with the "Filewriter" method because we use that to write out a batch file, so I figured it would be easy. I thought someone on here might know of an easier way...
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
You mean the FileWriter class? What does that have to do with jsp? Is it just that you've made a xml file in a jsp (why would you want to do that if you weren't going to send it back to the user?) and you want to save it to a file?
 

SP33Demon

Lifer
Jun 22, 2001
27,928
143
106
Originally posted by: kamper

And there are far more powerful methods for generating xml based on that idea (tag libraries/xsl etc.) if what you want to do is send the xml back to the user. But it's kinda hard to tell if thats what he wants to do.
Thanks amdfanboy/kamper, but I don't think that was what I was trying to do? What I need to do is to pass a value (say #4567843) by having the JSP page write this value into a separate XML file into a specified directory (say \\anandtech\directory\). The web application (which is written in J.script/JSP) will run, and at a certain point in the process, will write this XML file out. So if you looked in the \\anandtech\directory\ you would find XYZ.XML file with value #4567843 inside of this XML file (if you opened it). Currently, the JSP page can drop XYZ.bat file by using the Filewriter class, so I figured I could just bastardize this code to drop/make an XML file, but it's apparently not working. Hope this is a little more specific?

 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Ok, well FileWriter should work with any generic text data so as long as you have the xml that you need it shouldn't be any different that the bat file.

Are you having trouble generating the xml or just writing it? Is there code you can post?

And slightly off topic, this sounds like a job that would be better suited to a servlet rather than a jsp, or even some non-server related class that is just triggered by a servlet. Jsps are meant to send output back to an http client and theoretically it is bad practice to even embed plain java in your jsp (tags and the expression language are preferred).
 

SP33Demon

Lifer
Jun 22, 2001
27,928
143
106
Originally posted by: kamper
Ok, well FileWriter should work with any generic text data so as long as you have the xml that you need it shouldn't be any different that the bat file.

Are you having trouble generating the xml or just writing it? Is there code you can post?

And slightly off topic, this sounds like a job that would be better suited to a servlet rather than a jsp, or even some non-server related class that is just triggered by a servlet. Jsps are meant to send output back to an http client and theoretically it is bad practice to even embed plain java in your jsp (tags and the expression language are preferred).
Ok, here is the code. I was having trouble actually generating the XML file... :)

FileWriter fw = new FileWriter ("\\\\webdirectory\\temp\\" + "CHK-" + ItemNumber + ".xml", false);
BufferedWriter br = new BufferedWriter (fw);
PrintWriter pw = new PrintWriter (br);
pw.println ("<Map>" + "<trackingNumber>" + ItemNumber + "</trackingNumber>" + "</Map>" );
pw.flush();
pw.close();
br.close();
fw.close();

 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Ok, that looks good (except for the lack of try/finally blocks, I assume you left those out for clarity ;)). Is there still a problem then?
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: kamper

And there are far more powerful methods for generating xml based on that idea (tag libraries/xsl etc.) if what you want to do is send the xml back to the user. But it's kinda hard to tell if thats what he wants to do.

All I was trying to point out was the headers. I now see that's not want he wants to do.
 

SP33Demon

Lifer
Jun 22, 2001
27,928
143
106
Originally posted by: kamper
Ok, that looks good (except for the lack of try/finally blocks, I assume you left those out for clarity ;)). Is there still a problem then?
Hi guys, yes it finally worked... the problem was with permissions writing on that share drive, so I just set it to write to another one. Thanks for all the help... :)