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?
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With