SV: [thelist] JSP question

Marcus Andersson marcan at home.se
Tue Oct 21 13:30:10 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") != null) {
    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.


>Have I missed something? Also how do you get weblogic to show the whole
error on the page instead of just 500 -- internal server error?

If you do the try/catch yourself and use the JspWriter out to output it
(this should work in any servlet container):
try {
  // do stuff here
}
catch(Exception e) {
  PrintWriter writer = new PrintWriter(out);
  e.printStackTrace(writer);
}

Then the stack trace will be printed to the output.

There is other way of doing this like setting an error page for your
jsps but that's a little bit more complicated (not very much though, so
if you want more on that then I can give you)so...

Btw: You don't have your browser set to show friendly http error
messages, do you?

/Marcus



More information about the thelist mailing list