First look at the space of spec R as a set. Review the characterization of maximal and prime ideals in a direct product. An ideal in R is prime iff it is the direct product of a prime ideal Pi in Ri and all the other component rings. Sure enough, this is the union of all the points across spec Ri.
In fact this defines a canonical injection. The point Pi in spec Ri maps into spec R by crossing Pi with all the other rings, thus producing the point P in spec R. This map is an embedding, and together, all the spectra from the component rings cover spec R.
Consider the closed set vE in spec R, where E is an ideal. Write E as the direct product of ideals Ei. Now a prime ideal P, with a proper projection Pi in Ri, fails to contain E if Pi does not contain Ei. Apply this criterion as i runs from 1 to n, and vE includes all the points of vEi, across all the component rings. In other words, vE is the union of closed sets in the individual spaces.
The union of one closed set drawn from spec Ri remains closed in spec R, hence the injection of spec Ri into spec R is a continuous function. Also, the subspace determined by spec Ri inside spec R is both open and closed. Spec R includes an independent, disconnected subspace for each ring Ri.
The above reasoning remains valid if R is an infinite direct sum of component rings, but remember, the resulting ring does not contain 1. That's ok; 1 is not required to derive spec R.
How bout the converse?
Remember that all information about the nil radical is lost when viewing spec R, so assume rad(0) is 0, or, mod out by rad(0) to create a reduced ring. Now every nonzero x in R evades at least one prime ideal.
If a subspace is open and closed, then there are two closed sets vE and vF that are disjoint, and cover spec R. If x ∈ E times y ∈ F is nonzero then there is some prime ideal P that does not contain ef, and vE∪vF does not cover spec R. Therefore the ideals E and F are orthogonal.
If some nonzero x lies in E and F then some prime ideal P is not in vE or vF, hence E and F are disjoint ideals. They are disjoint R modules, and each element of R is a unique sum from E cross F.
If E and F do not span 1 then they lie in some maximal ideal P, which is common to both vE and vF. Thus there are elements x ∈ E and y ∈ F such that E+F = 1. Since linear combinations are unique, we can write, unambiguously, x+y = 1.
Square this equation to get x2+y2 = 1. Again, the representation of 1 is unique, so x2 = x and y2 = y. In other words, x and y are orthogonal idempotents.
For any z in R, z*1 = 1*z. This means zx = xz, and zy = yz. The idempotents commute with R. This is sufficient to prove R is the direct product of rings E and F.
If spec R separates into finitely many disjoint spaces, apply the above repeatedly, and R is the finite direct product of rings.
As a corollary, the spectrum of a local ring is connected. If it were disconnected, one could produce a maximal ideal for each component.