Thread: Why we cant override _jspService() ?

Forum : Java Server Pages (Jsp)   23-8-2017 09:53:53 AM
User Image
Sangram94

Newbie

Joined: Jun 25, 2017

Points: 100

Threads: 6

Posts: 9

Answer Icon Why we cant override _jspService() ?

| Quote Date : Aug 23, 2017    Views:743    

Why we cant override _jspService() ?

tags: jsp

Comments

User Image
chowdaka5

Newbie

Joined : Jun 28, 2017

Points : 145

Threads: 31

Posts: 101

Answer IconRe: Why we cant override _jspService() ?

Reply Date : Aug 23, 2017

No, at the time of compilation web container (jsp engine) always generates _jspService() method in generated class automatically means whenever we submit the jsp to the jsp engine it will generates one corresponding servlet class which resembles jsp.So in that servlet jsp engine will generates -jspService() method .So if we write externally then servlet contains two -jspService() methods which raises compilation error.

User Image
Deshmukh G

Newbie

Joined : Apr 21, 2017

Points : 120

Threads: 41

Posts: 25

Re: Why we cant override _jspService() ?

Reply Date : Aug 23, 2017

_jspService() method is called every time a request comes into jsp page during its lifecycle.
The (_) underscore sign indicates that this method is generated by Container and hence cannot be overriden.
The jsp code written by us goes in _jspService() because this is implicitly implemented.
In case we  tries to override it explicitly, JSP compliler will give an error saying "the method is already implemented and cannot override".

User Image
tVivek

Newbie

Joined : Jun 25, 2017

Points : 100

Threads: 0

Posts: 8

Re: Why we cant override _jspService() ?

Reply Date : Aug 23, 2017

Because, if we override the _jspService(), the code generated by jsp compiler. So it would be end with two _jspService() (First one is yours and second one is generated by compiler), that's responsible for compilation error.

User Image
Samira

Newbie

Joined : Jun 11, 2017

Points : 100

Threads: 0

Posts: 4

Re: Why we cant override _jspService() ?

Reply Date : Aug 23, 2017

Actually _jspService() method are goes under the life cycle of jsp,any data we write will goes to the _jspService() method because we are implicitly implement it.so if we override _jspService() method,then we will get error.

Load More

No More Comments