Step 1: Convert everything to tan x.
Divide the numerator and the denominator by \(\cos^2 x\). We have \(\sin 2x = 2\sin x\cos x\), so \(\frac{1 + \sin 2x}{\cos^2 x} = \sec^2 x + 2\tan x = 1 + \tan^2 x + 2\tan x\).
\[ \frac{\sin^2 x}{1 + \sin 2x} = \frac{\tan^2 x}{(1 + \tan x)^2} \]
Step 2: Substitute t = tan x.
Then $dx = \frac{dt}{1 + t^2}$. When $x = 0$, $t = 0$. When $x \to \frac{\pi}{2}$, $t \to \infty$.
\[ I = \int_0^{\infty} \frac{t^2}{(1 + t)^2(1 + t^2)}\,dt \]
Step 3: Split into partial fractions.
The integrand breaks up as follows (checked by combining the terms back).
\[ \frac{t^2}{(1+t)^2(1+t^2)} = \frac{t}{2(1+t^2)} - \frac{1}{2(1+t)} + \frac{1}{2(1+t)^2} \]
Step 4: Integrate each term.
The three terms integrate to a logarithm in $1 + t^2$, a logarithm in $1 + t$, and a power term.
\[ F(t) = \frac{1}{4}\log(1 + t^2) - \frac{1}{2}\log(1 + t) - \frac{1}{2(1 + t)} = \frac{1}{4}\log\frac{1 + t^2}{(1 + t)^2} - \frac{1}{2(1 + t)} \]
Step 5: Apply the limits.
As $t \to \infty$, the ratio $\frac{1 + t^2}{(1 + t)^2} \to 1$, so the log term tends to 0. The last term also tends to 0. So $F(\infty) = 0$.
At $t = 0$, $F(0) = 0 - \frac{1}{2} = -\frac{1}{2}$.
\[ I = F(\infty) - F(0) = 0 + \frac{1}{2} = \frac{1}{2} \]
Final Answer:
Both routes give the same value.
\[ \boxed{\frac{1}{2}} \]