Concept:
To solve this integral, we use the definite integral property
$\int_{0}^{a} f(x) \, dx = \int_{0}^{a} f(a-x) \, dx$.
This allows us to eliminate the $x$ term in the numerator, which is a common technique for integrands involving $x \sin x$ or $x \cos x$.
Step 1: Apply the integral property.
Let $I = \int_{0}^{\pi} \frac{x \sin x}{1 + \cos^2 x} \, dx$.
Replacing $x$ with $(\pi - x)$:
\[ I = \int_{0}^{\pi} \frac{(\pi - x) \sin(\pi - x)}{1 + \cos^2(\pi - x)} \, dx \]
Since $\sin(\pi - x) = \sin x$ and $\cos(\pi - x) = -\cos x$ (so $\cos^2(\pi - x) = \cos^2 x$):
\[ I = \int_{0}^{\pi} \frac{(\pi - x) \sin x}{1 + \cos^2 x} \, dx \]
Step 2: Sum the two forms of the integral.
Adding the original $I$ and the modified $I$:
\[ 2I = \int_{0}^{\pi} \frac{x \sin x + (\pi - x) \sin x}{1 + \cos^2 x} \, dx \]
\[ 2I = \int_{0}^{\pi} \frac{\pi \sin x}{1 + \cos^2 x} \, dx \implies I = \frac{\pi}{2} \int_{0}^{\pi} \frac{\sin x}{1 + \cos^2 x} \, dx \]
Step 3: Integrate using substitution.
Let $u = \cos x$, then $du = -\sin x \, dx$.
When $x = 0, u = 1$; when $x = \pi, u = -1$.
\[ I = \frac{\pi}{2} \int_{1}^{-1} \frac{-du}{1 + u^2} = \frac{\pi}{2} \int_{-1}^{1} \frac{du}{1 + u^2} \]
\[ I = \frac{\pi}{2} \left[ \tan^{-1} u \right]_{-1}^{1} = \frac{\pi}{2} \left( \frac{\pi}{4} - \left( -\frac{\pi}{4} \right) \right) \]
\[ I = \frac{\pi}{2} \left( \frac{\pi}{2} \right) = \frac{\pi^2}{4} \]