SV: [thelist] JSP question

Marcus Andersson marcan at home.se
Tue Oct 21 10:38:15 CDT 2003


><% String orderInfo = "1"; %>
>// below is the page with the conditional DIV indside.. <jsp:include
page="includes/dashboards.jsp"/>

You have to pass your variable on to the page you include. There is a
way to do it with <jsp:param .../> to do this but I prefer the following
instead (shorter):

<%
  request.setAttribute("orderInfo", orderInfo);
%>

>inside the "dashboards.jsp" page I tried this:

><% if(orderInfo.equals("1"))...show DIV %> (psuedo)

Do the following in dashboards.jsp to get the paramater you set
<%
  String orderInfo = "1" // default value
  if(request.getAttribute("orderInfo")) {
    orderInfo = (String)request.getAttribute("orderInfo");
  }
%>

Some folks would say that you shouldn't do like this because you
shouldn't mix logic with presentation. I say that it's okay if your
building pretty simple pages with not too much logic. If you start to
get a lot of logic in your pages I would recommend to break the logic
out of the pages and use a framework like WebWork, Maverick (Struts, but
I don't like it) and some nice templating system like Tiles, Sitemesh
etc.

There will, btw, simpler to build nice looking jsp when JSP2.0 is ready.
You can download a beta version of Tomcat5.0 from Apache Jakarta which
is the reference implementation of the JSP2.0 spec.

/Marcus



More information about the thelist mailing list