Custom JSP tag. Lets you prepare and output images in your JSP pages. Tag encodes the graphical context (java.awt.Graphics2D) and outputs it in JPEG format For example, suppose you have the following definition in file pic.jsp:
<%@ page import="java.awt.*" %> <%@ taglib uri="taglib.tld" prefix="pic" %> <pic:JPEG width="125" height="125"> <% graphics.setColor(Color.blue); graphics.fillRect(0,0,125,125); graphics.setColor(Color.yellow); graphics.drawString("Hello",30,60); %> </pic:JPEG> In this example Java code in tag's body draws blue rectangle and writes in yellow Hello. You may use pic.jsp in your JSP/HTML code as a source for image: <img src="pic.jsp" width="125" height="125" border="0"> More complex example (rotated text):
<%@ page import="java.awt.*,java.awt.geom.*,java.awt.font.*" %> <%@ taglib uri="taglib.tld" prefix="pic" %> <pic:JPEG width="125" height="125"> <% AffineTransform af = new AffineTransform(); af.translate(100.,10.); af.rotate(Math.PI / 2); FontRenderContext renderContext = new FontRenderContext(null, false, false); graphics.transform(af); TextLayout layout = new TextLayout( "Rotated 90 grad", graphics.getFont(), renderContext); layout.draw(graphics, 0, 0); %> </pic:JPEG> In other words this tag defines a graphical context (java.awt.Graphics2D) you may
use in tag's body for your drawings. Name for this variable is graphics.
Tag's body is any Java code that does something with this context. In the above mentioned
example we've used scriptlet. You may of course call any bean for example. And all this
code works in your JSP environment so you may use of course all available JSP objects.
For example:
<%@ taglib uri="taglib.tld" prefix="pic" %> <pic:JPEG width="125" height="125"> <% // call some static method and pass parameter from request com.acme.drawBean(graphics, request.getParameter("something")); %> </pic:JPEG> Tags are: JPEG Encodes body and outputs data in JPEG format. Attributes are: 1) width image width
for downloading: Library: jpegtag.jar Description: taglib.tld See also Coldtags suite - the largest collection of custom JSP tags.
|
Also in Coldtags:
|