Bus from Tokyo to Osaka:
http://www.japan-guide.com/e/e2366_osaka.html#tokyo Ferry from Osaka to Shanghai:
http://www.seejapan.co.uk/transport/sea/international.htmlMaybe not that much cheaper than flying, and WAY slower.
I've taken the overnight bus between Osaka and Tokyo for about US$50 each way and it's been really comfortable--seats that recline a lot, big heavy curtains making everything dark. I'm 5'7, though, so can't talk about comfort for anyone taller.
I've never taken the Shanghai ferry (or even been to Shanghai--yet!) but I've taken overnight ferries within Japan and I love them. Even the cheapest no-cabin option comes with a little pad to roll out and a blanket to use in your sleeping spot, and a sento, like a bathing room, where you can shower and soak in a hot bath. You can take the subway right out to the Osaka harbor, where the ferries leave from.
For August travel, booking ahead might be a good idea--and buying round trip rather than one way tickets should save you a little too.
Okay, I know you probably don't have enough time to add that much travel time into your trip, but it is an option!