20060425 Tuesday April 25, 2006

Passing Objects to JSP Include Pages

When working with plain old JSP, it is often useful to extract reusable bits into separate JSP files that you include in your pages via the jsp:include tag. However, sometimes you need to be able to pass objects to those included pages. The jsp:include tag allows a jsp:param sub-tag that can be used to pass String values, but what if you need to pass another object type?

There are two easy ways to do this, but first you need to decide whether you need the object to be persistent across multiple requests. If so, then your best bet is to use session.setAttribute(). For example, let's assume I have a HashMap called myMap that I want to persist for the duration of the user session.

HashMap myMap = new HashMap();
myMap.put("myValue","test");
session.setAttribute("myMap",myMap);

Then from your included JSP page (or any other JSP pages after the session has been initialized), you would call session.getAttribute() to retrieve your object:

HashMap myMap = (HashMap)session.getAttribute("myMap");

The downside with this approach is that it wastes memory if you really only need the HashMap to persist for the duration of the request, i.e. you just want to pass it to the included JSP page and then be done with it. I better approach for this situation is to use the request object:

request.setAttribute("myMap",myMap);

Then in your included JSP page:

HashMap myMap = (HashMap)request.getAttribute("myMap");

 

Posted by rickg ( Apr 25 2006, 11:32:44 PM PDT ) Permalink Comments [4]
20060413 Thursday April 13, 2006

Stuck at "Windows is shutting down"

My Windows XP machine has been hanging on shutdown and restart. It would get all the way to the "Windows is shutting down" screen, then just sit there. I once left it on all night to no avail. I tried killing services, etc. to no avail.

After extensive searching on the web, I found one site that mentioned moving the paging file as the cure for a shutdown problem. I had recently moved my page file from my C drive to another RAID striped disk.

Today I moved the swap file back to my C drive, and set the size to the "recommended" value mentioned in the control panel (it had been set to slighly more than my physical memory). My shutdown problem is now gone. Not sure if it was moving drives that fixed it, or bumping it up to the recommended value. At some point I will move it back to the striped drive, but with the larger page file and see if I still have the problem.

Update: I tried copying the swap file back to the striped volume again, and the shutdown problem returned. Maybe it is an issue with NVidia RAID on the nForce 4 motherboard. Anyway, hope this helps somebody else in the future.

Posted by rickg ( Apr 13 2006, 07:01:46 AM PDT ) Permalink Comments [0]