If your knowledge of J2EE is limited I would say that expecting to be able to move easily from one server to another could be quite risky.
If you are coding by trial and error you are likely to start taking advantage of the specific implementation details of the application server that you start to work with, this then makes porting difficult as you need to identify each time that this has happened.
I have lost count of the number of times that I have seen posts saying 'This works on applicatino server X why doesnt it work on JBoss' where developers have assumed that the behaviour they have discovered by trial and error will be the same across all J2EE implementations.
On the other hand if you understand the specifications first you should be able to make sure that you don't use features that are application server specific or at the very least you will have an understanding of where your implementation is making use of functionality outside of the specification.
So briefly developing an application against a J2EE application server does not automatically make your application portable across all J2EE application servers however developing against the specifications greatly reduces the chance of you encoutering porting issues.