$I = \int_{0}^{\pi}\frac{xsinx dx}{1+cos^2x}$
$I = \int_{0}^{\pi}\frac{(\pi-x)sin(\pi-x) dx}{1+cos^2(\pi-x)}$
$I = \int_{0}^{\pi}\frac{(\pi-x)sinx dx}{1+cos^2x}$
$I = \int_{0}^{\pi}\frac{\pi sinx dx}{1+cos^2x} - \int_{0}^{\pi}\frac{xsinx dx}{1+cos^2x} $
$2I = \int_{0}^{\pi}\frac{\pi sinx dx}{1+cos^2x} $
$\text{integrating using substitution:- } $
$cosx = t \rightarrow -sinxdx = dt \rightarrow sinxdx = -dt $
$\text{limits}$
$\text{when } x = 0 \text{ then } t = 1$
$\text{when } x = \pi \text{ then } t = -1$
$2I = \int_{1}^{-1}-\frac{\pi dt}{1+t^2} $
$2I = \int_{-1}^{1}\frac{\pi dt}{1+t^2}$
$\text{Again, integrating by substitution as follow:-}$
$t = tanu \rightarrow dt = sec^2udu$
$\text{limits:-}$
$t = 1 \rightarrow u = \frac{\pi}{4}$
$t = -1 \rightarrow u = \frac{-\pi}{4}$
$2I = \int_{-\frac{\pi}{4}}^{\frac{\pi}{4}}\frac{sec^2u du}{1+tan^2u}$
$2I = \int_{-\frac{\pi}{4}}^{\frac{\pi}{4}}\pi du$
$2I = \pi[\frac{\pi}{4} +\frac{\pi}{4}] $
$I = \frac{\pi^2}{4} \leftarrow \text{ANSWER}$