Chris Tucker wrote: > > Hi all, > > I was wondering how other people approach the problem of passing parameters > to include files (or even if this is really something that it's a good idea > to do...). For example, say I want to specify some button text for an > included file, I may want pass a parameter called "buttontext" with the > value "Hello". The way I've been approaching this so far is to encode the > parameters as a query string on the include URL, e.g. > <jsp:include page="test.jsp?buttontext=Hello" /> > but this doesn't really scale up to anything more than simple textual > arguments. I could add stuff to the session or context, allowing me to use > more complex objects, but I don't want to be creating a load of > interdependencies as far as attribute naming etc. is concerned between an > include file and the file including it. Ideally, I'd like to just be able > to parameterise the include as one would a method. > > Any suggestions?
For text parameters, you can use nested param elements instead of the query string: <jsp:include page="test.jsp"> <jsp:param name="buttontext" value="Hello" /> </jsp:include> This saves you from having to convert special characters in the parameter value (URL encoding). For complex data structures, you can use request attributes: <jsp:useBean id="foo" class="com.foo.MyComplexData" scope="request"> <jsp:setProperty name="foo" property="bar" value="<%= new Date() %>" /> ... </jsp:useBean> <jsp:include page="test.jsp"> The included page is processing the same request, so it has access to all request scope data. Hans -- Hans Bergsten [EMAIL PROTECTED] Gefion Software http://www.gefionsoftware.com Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com