UpdateInventoryTag.java.

Graphic Java
Create XML files using JSP
David Geary
Listing 2. UpdateInventoryTag.java.


package com.companyName.tags.inventory;

import java.io.*;
import javax.servlet.jsp.tagext.TagSupport;
import com.companyName.beans.model.Inventory;

public class UpdateInventoryTag extends TagSupport {
	private Inventory inventory = new Inventory();
	private String filename;

	public void setFilename(String filename) {
		this.filename = filename;
	}
	public int doEndTag() {
		File tempDir = (File)pageContext.getServletContext().
						getAttribute("javax.servlet.context.tempdir");
		File xmlFile = new File(tempDir.getAbsolutePath() + "/" + filename);
		try {
			inventory.printXml(new PrintStream(
									                new FileOutputStream(
									                xmlFile)));
		}
		catch(IOException ex) { }

		return EVAL_PAGE;
	}
}

About the Author

David Geary was the lead engineer for the Java Management API GUI toolkit, and is now an independent Java consultant. David is the author of Graphic Java—Mastering the JFC. He can be contacted at sabreware@tri-lakesonline.net.

Featured

Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.