Jhanas are the mental states (consciousness) of brahma realms.
When a person willfully avoids akusala kamma and stays away from kama assada for a prolong period of time, he/she naturally gets to anariya jhanas (vivicceva kāmehi vivicca akusalehi dhammehi…).
We can get to jhanas by cultivating brahma viharas (metta, mudita, karuna, upekkha).
Jhanas can also be achieved by focusing one’s mind on a suitable object like breath/kasina/mantras/image of a god, etc. That is Samatha meditation.
However, just getting to jhanas will not get one to Nibbana because the anusayas (mental fermentations) are only suppressed (in anariya jhanas), they are not removed. The anusayas and sanyojanas can be removed only by cultivating wisdom (panna) of Anicca, Dukkha, Anatta/Paticca Samuppada/Four Noble Truths.
Anariya yogis believed (and still believe) that they can get to Nibbana by avoiding akusala kamma and staying away from kama assada (sense pleasures). This is known as “silabbata paramasa”. This wrong view is broken at the Sotapanna stage.
But getting to jhanas is not bad. It’s a very good gati. Our Bodhisatta naturally got to jhana when he was just a seven year old boy sitting under the shade of a tree. It was due to his gati from past lives.
There are three main purposes of cultivating jhanas:
(1) It is used to gain various nanas like pubbenivasanussati nana (knowledge of past lives), cutupapada nana (knowledge of births in other realms), etc…
(2) It is used to gain iddhi powers, for doing many supernatural feats which is beyond our limited human capacity. Lord Buddha performed many supernatural miracles at various occasions to generate faith in the minds of people towards the Buddha, Dhamma, Sangha.
(3) It is used for generating blissful feelings/sensations. When Lord Buddha was suffering from physical ailments in his old age, He overcame those painful feelings by abiding in the jhanas.