Well, like a lot of things, it's a little bit of both. There's a lot of things you can do that will make confidently approaching a solo easier (and confidence IS key), here's some stuff that I find exceptionally helpful:
1. Have the song form MEMORIZED. As in, be able to take maybe one glance at the chart and then never have to look at it again for the duration of the tune. It's one less mental activity that you need to devote yourself to onstage, and life becomes a lot simpler when you can stare off into space (or watch your bandmates intently for dynamic cues, etc) and do your thing. Also, chicks dig it when you can say stuff like "Baby, I've got the WHOLE REAL-BOOK committed to memory. Test me!" (Protip: for having over 500 tunes in it, there really are maybe 20 forms in the entire Real Book and a handful of 'outlier' tunes (thanks Chick Corea!) With flash-cards and some solitude, you can do it in two weekends and then never have to worry about it again)
2. Have the song melody (the 'head') memorized, and be able to play it at least as well as the horn player in your band. From a soloing perspective, having both #1 and #2 accomplished will make it *extremely* difficult to ever get lost in a song form, either while walking or soloing. It will also help implant certain melodic ideas into your subconscious that, when expressed through your solo, will 'just make sense' to yourself and the listener.
3. Know your modes, and know what chords to play them on. For me, this is a big help when I'm asked to accompany or solo over a completely unfamiliar tune. Knowing that "Ah hah, these next four beats should be something approaching 'Dorian', followed by four beats of 'Mixolydian', and then maybe four beats of 'Ionian' or (if I'm feeling saucy) 'Lydian'" helps me analyze a tune and frankly commit it to memory a LOT faster. It also helps when I have to play a tune in a different key (generally when working with a vocalist who is... less than prepared ;-) ) because I can just mentally convert something like "Cm | F7 | Bb" to "ii | V | I" and adjust my 'root' chord accordingly
4. Know technique. This one is my latest challenge (not that I've got #s 1-3 anywhere NEAR under my belt...) that I found out about when I started studying jazz guitar. What really brought it all together for me was when I realized that these 'mindless' scale drills in 3rds, 4ths, 5ths, 6ths, etc were NOT just about muscle memory (although that's a big part of it), but they are equally about INTERVAL memory, i.e. committing that interval to your subconsciousness in such a way that you can easily mentally hear and identify that interval. For me at least, it's INCREDIBLY satisfying to hear some BLINDING horn lick go by, and just be able to say "Ah hah, that's not THAT crazy, he's merely doing asending triad 16th-notes starting on, mmmm, sounds like the ii". I might not be able to DUPLICATE it quite yet, but it no longer sounds like unattainable, completely astounding 'scribbling' of notes. I'd go to a really good teacher to help get this one under your belt, but to get yourself started take your metronome, set it to something nice and slow, and just play a major scale ascending and descending in 3rds. Then do it backwards. Then speed it up. Only go to the next 'speed' or whatever when you can do the previous one cleanly and/or when you get bored. Experiment and try to find out HOW to trick yourself (alternate ascending/descending 3rds at 210, perhaps?). It sounds like a pain in the ass, but once you get into it, its actually a lot of fun! Sit back and watch as your ears just OPEN to the tonal possibilities in yours and others solos. Speaking of other's solos...
5. Transcribe! Go get yourself a copy of the software program 'transcribe' at
www.seventhstring.co.uk. Load up your favorite version of your favorite tune by your favorite players, and slow down that bass solo/walking line/guitar riff/whatever. Break out some good ol' sheet music, and with your axe in hand write that **** down. Again, it's about cramming more and more different things into your subconscious in a specfic, ordered way that will make sense to your brain. If you get to the point where you can play J. Awesome Bassist's solo over Stella By Starlight slowed down, it's a matter of hours (as opposed to weeks or months) with the metronome before you can play it 'at speed'. Once you've got it at speed (or heck, even when you just have it down 'slow') you'll probably find nitpicky little things that you'd change if you could. What's that? You've got the notation in front of you/committed to memory already? Great, you can modify the lick/solo/line however you want. Congratulations, you've transformed a 'stolen' line into something unique and special to you!
Remember: a good player practices until he gets it right. A legend practices until he can't get it wrong. Hope this helps!
--Lee