$I=\large\int \limits_0^{\pi} \frac{x \sin x}{1+\cos ^2 x}$----(1) using the properties of integrals

$I=\large\int \limits_0^{\pi} \frac{(\pi-x) \sin (\pi -x)}{1+\cos ^2(\pi-x)}dx$

$I=\large\int \limits_0^{\pi} \frac{(\pi-x) \sin x}{1+\cos ^2x}dx$----(2)

Adding (1) and (2)

$2I=\large\pi \int \limits_0^\pi \frac{\sin x}{1+\cos ^2x}dx$

Put $\cos x =t$

$-\sin x dx =dt$

x | 0 | 1 |

t | $\pi$ | -1 |

$=>2I=\pi \int \limits_{+1}^{-1} \frac{-dt}{1+t^2}$

$=\pi \int \limits_{-1}^1\frac{dt}{1+t^2}$

$2I=-\pi \bigg[\tan^{-1}t\bigg]_{-1}^1$

$2I=+\pi \bigg[\tan^{-1}(1)-\tan^{-1}(-1)\bigg]$

$2I=\pi\bigg[\large\frac{\pi}{4}+\frac{\pi}{4}\bigg]$

$=\large\frac{\pi^2}{2}$

Therefore $I=\large\frac{\pi^2}{4}$