Answer
$\frac{\pi^2}{4}$
Work Step by Step
Using substitution $u = \pi - x\,\,\,du=-dx$, we have
$\int_{0}^{\pi}\frac{x\sin x}{1+\cos^2x}\, dx = \int_{0}^{\pi}\frac{(\pi-u)\sin u}{1+\cos^2u}\, du$
There is no change to $\sin x $ and $\cos x$ since $\sin(\pi-x)=\sin x$ and $\cos^2(\pi-x)=(-\cos x)^2=\cos^2x$, at the same time $x$ and $u$ are dummy variables which means they are interchangeable, therefore
$\int_{0}^{\pi}\frac{x\sin x}{1+\cos^2x}\, dx =\frac{\pi}{2} \int_{0}^{\pi}\frac{\sin x}{1+\cos^2x}\, dx$
Now, by substitution $t=\cos x\,\,\,dt=-\sin x\, dx$, thus
$\int_{0}^{\pi}\frac{x\sin x}{1+\cos^2x}\, dx =\frac{\pi}{2} \int_{0}^{\pi}\frac{\sin x}{1+\cos^2x}\, dx=\frac{\pi}{2}\int_{-1}^{1}\frac{1}{1+t^2}\,\,\, dt=\frac{\pi}{2}\biggl[\arctan t\biggr]_{-1}^{1}=\frac{\pi^2}{4}$
Remark : $\int\frac{1}{1+x^2}\, dx=\arctan x +C$