If on the other hand, you don't want to 'pre-load' the entire contents of boxB with all possible values, you are forced into a server round-trip.
I'm not sure if this qualifies as an 'algorithm', but here's a few of my thoughts.
form.jsp contains boxA and boxB.
BoxA (and boxB I suppose) are inside a form.
Inside getBoxB, you retrieve the current value of boxA, and use it to query your database (or whatever) for the corresponding values of boxB, which you might store into a LinkedHashMap (key would be the value of the boxB, value would be the displayed value of boxB).
This linkedHashMap would then be placed into the request, along with the 'current' value of boxA.
You would also retrieve the values of boxA, although you might want to be clever and do this once, and stick it in the application namespace (ServletContext for servlets, 'application' in a JSP page -> they're the same thing).
The servlet then forwards along (back) to form.jsp
form.jsp will use the 'current' value of the boxA parameter to determine which element of boxA is currently highlighted, when it builds boxA dynamically.
it will iterate over the map to build boxB dynamically.