So I started writing my own object oriented rendering JSP taglib as I could not find anything like that anywhere. Ok I just played around with taglibs in general because I had no idea how to write Java tags, I only did JSP tags before.

public class SampleTag extends TagSupport {

	private Object o;

	public void setPageContext(PageContext pageContext) {


	public int doStartTag() throws JspException {

		try {
			ServletRequest req = new HttpServletRequestWrapper((HttpServletRequest) pageContext.getRequest()) {
				private final Map<string, object=""> wrappingAttributes = new HashMap<string, object="">();

				public void setAttribute(String name, Object o) {
					wrappingAttributes.put(name, o);

				public Object getAttribute(String name) {
					Object o = wrappingAttributes.get(name);
					if (o != null) {
						return o;
					return super.getAttribute(name);

			req.setAttribute("something", o);
					.include(req, pageContext.getResponse());
		} catch (ServletException e) {
			// TODO Auto-generated catch block
		} catch (IOException e) {
			throw new JspException(e);

		return SKIP_BODY;

	public void setSomething(Object o) {
		this.o = o;


I must admit it is not very pretty (yet) but it does some stuff. For now I am able to pass a variable something through the tag to another JSP (blubb.jsp). And as I put the object in my request wrapper it can be used in the blubb.jsp. I used the wrapper because I did not want to write in my actual request (who the fuck knows what will happen if I mess with that :P ). But the question is what happens if I use the tag within my blubb.jsp again? Is a new instance of the tag class created on each use and will there be problems with the wrapped request then?

Also is this the best way to include a JSP? you might wonder why I need to flush the out at the beginning of the method… well if I don’t do that it my included jsp is rendered first before the jsp using my tag… but this flush causes the site being transfered to the browser before it is completely rendered which kind of gives me cancer. I cunt pasted that bloody dirty piece of code from here

Also here is the tld of my little taglib (copy pasta from JSTL core):

<!--?xml version="1.0" encoding="UTF-8"?-->
<taglib xmlns="" xmlns:xsi="" xsi:schemalocation="" version="2.1">
	<display-name>Sample taglib</display-name>