Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can jsp_service() method be overridden?

Tags:

jsp

servlets

I know that the jsp_service() method cannot be overridden, but one of my friends said that we could use scriptlets in JSP to override the method and could do whatever we need in that method.

Can anyone explain it's true?

like image 581
developer Avatar asked Dec 27 '22 02:12

developer


1 Answers

Not Its not true.

Take a sample JSP:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>
    </body>
</html>

If you check generated Servlet for this JSP. You will find _jspService method containing HTML code as out.write

Why ?

Since what ever we wrote code in the JSP will be placed in _jspService() of generated servlet class(from JSP) .means _jspService() is already imlimented by us.So if we attempted to override _jspService() it will give a compilation error regarding the method _jspService() is already defined.

Read More why jspService() cannot be overridden?

like image 96
Hardik Mishra Avatar answered Jan 31 '23 10:01

Hardik Mishra