How to root Xperia P device How do I get root access for my Xperia P device runing Jelly Bean(4.1)?

Is it required to unlock bootloader before trying to root the phone?
Okay here is how to root  without unlocking bootloader for XP Jellybean. This is confirmed working and do it in your own risk. 

Note: 
Charge your phone to 100% before doing this and back up contact,message and any other installed app. 


Download and install Flashtool (If you dont know how to flash using flashtool follow this tutorial
Download Sony Xperia P_6.1.1.B.1.75_Generic World from here
Put the ftf file inside the firmware folder of flashtool
Turn Usb Debugging on in your phone
Shut down your Xperia P
Press the lightning icon inside flashtool
Select FLASHMODE (NOT FASTBOOT)
Choose the Sony Xperia P_6.1.1.B.1.75_Generic World ftf file for XP 
When flashtool ask you to connect your device, insert USB cable first in your phone then hold Volume Down Button and insert the other end of USB in your PC
Wait till it finish
Disconnect your phone and power on. You are back in ICS 
Flash 0.559 kernel via flashtool
Remove the phone from PC, reboot the phone
Connect the phone to PC
Open flashtool hit the root button
When you see "waiting for restore to finish" open your phone and run Backup&amp;Restore app and restore RootMe.tar file.
Wait until Flashtool do the rest of work
When u r done flash .75 kernel via flashtool reboot the phone
Download CWM
Extract the folder
Connect your phone to the pc with USB debugging
Click on install.bat
Download JB KERNEL and PRE ROOTED JB
Put it on your SD card
Well Now shut down you Xperia P
Turn it on
Enter CWM Recovery by pressing volume down (dont hold the volume button put press repeatedly move up and down using volume button select using power button)
Mount System
Mount Data
Mount Cache
Flash the JB Kernel Zip
Again Mount System
Mount Data
Mount Cache
Flash the JB_prerooted_6.2.A.0.400.zip
Do Not Reboot !!
Wipe Data/Factory Reset
Reboot !!


It take some minutes, But just wait with patience

For the 1st time you may get FC from Thememanager and Timescape

Enjoy Rooted JB !!!

Source: XDA