Step 1: Let
\[
I=\int_{0}^{\pi} \frac{x\sin x}{1+\cos^2 x}\,dx
\]
Step 2: Replace $x$ by $\pi-x$ in the integral:
\[
I=\int_{0}^{\pi} \frac{(\pi-x)\sin x}{1+\cos^2 x}\,dx
\]
Step 3: Add the two expressions for $I$:
\[
2I=\int_{0}^{\pi} \frac{\pi\sin x}{1+\cos^2 x}\,dx
\]
Step 4: Take $\pi$ outside the integral:
\[
2I=\pi\int_{0}^{\pi} \frac{\sin x}{1+\cos^2 x}\,dx
\]
Step 5: Substitute $u=\cos x$, so $du=-\sin x\,dx$.
When $x=0$, $u=1$; when $x=\pi$, $u=-1$.
\[
\int_{0}^{\pi} \frac{\sin x}{1+\cos^2 x}\,dx
=\int_{-1}^{1} \frac{du}{1+u^2}
=\left[\tan^{-1}u\right]_{-1}^{1}
=\frac{\pi}{2}
\]
Step 6: Hence,
\[
2I=\pi\cdot\frac{\pi}{2}=\frac{\pi^2}{2}
\Rightarrow I=\frac{\pi^2}{4}
\]