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 [email protected].

Upcoming Training Events

0 AM
Visual Studio Live! San Diego
September 8-12, 2025
Live! 360 Orlando
November 16-21, 2025
Cloud & Containers Live! Orlando
November 16-21, 2025
Data Platform Live! Orlando
November 16-21, 2025
Visual Studio Live! Orlando
November 16-21, 2025