JSP Taghandler problem

[nobr]Hi,

I am running NetBeans 5.5 on XP Pro using java 1.6

I have a servlet called Controller which forwards the request to main.jsp

//Controller.java --

protectedvoid processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{

String id = request.getRequestURI();

id = id.substring(request.getContextPath().length());

if (id.equals("/")){

request.setAttribute("page","welcome.jsp");

}

else{

request.setAttribute("page", id);

}

RequestDispatcher dispatcher = request.getRequestDispatcher("main.jsp");

dispatcher.forward(request, response);

}

//--

main.jsp presents a table.

//main.jsp --

<%@taglib prefix="tritons" uri="./tlds/tritons.tld" %>

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Index</title>

</head>

<body>

<table border="1">

<tbody>

<tr>

<td colspan="0">

<jsp:include page="header.jsp" flush="true"/>

</td>

</tr>

<tr>

<td>

<a href="docs/testerone.jsp">tester one</a>

<br>

<a href="docs/testertwo.jsp">tester two</a>

</td>

<td>

<tritons:content/>

</td>

</tr>

</tbody>

</table>

</body>

</html>

//

tritons:content is described in tritons.tld

//tritons.tld

<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">

<tlib-version>1.0</tlib-version>

<short-name>tritons</short-name>

<uri>/WEB-INF/tlds/tritons</uri>

<tag>

<name>content</name>

<tag-class>fcexample.taghandlers.ContentHandler</tag-class>

<body-content>empty</body-content>

<display-name>Content</display-name>

</tag>

</taglib>

//-

ContentHandler is meant to insert the correct file in the table in main.jsp

//ContentHandler.java -

publicclass ContentHandlerextends TagSupport{

// Method called to begin tag processing

publicint doStartTag()throws JspException{

// attempt tag processing

try{

ServletRequest request = pageContext.getRequest();

ServletResponse response = pageContext.getResponse();

String page = request.getAttribute("page").toString();

request.getRequestDispatcher(page).include(request, response);

}

catch (ServletException SE){

System.out.println(SE.getMessage());

}

// rethrow IOException to JSP container as JspException

catch( IOException IOE ){

thrownew JspException(IOE.getMessage());

}

return SKIP_BODY;

}

//-

My problem is that on start up the welcome.jsp is displayed in the same

part of the table as header.jsp

But if i add

JspWriter out = pageContext.getOut();

out.println("Welcome.jsp");

then this text is displayed in the correct cell of the table.

Thanks in advance,

J[/nobr]

[5444 byte] By [dr.jgha] at [2007-11-27 9:08:05]
# 1

Aaargh...

Typical, I look every for the solution and only find when i post the problem.

Anyway the solution is in ContentHandler.java to replace

request.getRequestDispatcher(page).include(request, response);

with:

pageContext.include(page);

Apologies,

J

dr.jgha at 2007-7-12 21:45:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...