Reputation: 17208
I am new to the JSP related technologies. I faced a strange situation: works find with scriplet
<%
String username = request.getParameter("username");
if ( username != null && username.length() > 0 ) {
}
%>
But with declaration request object can not be found?
I read that when be define method or variable in declarations they are part of the servlet, from the servlet we can access request object. So why is this strange behavior?
Upvotes: 0
Views: 1607
Reputation: 129
JSP is converted into a servlet before compilation.
What you write inside a jsp scriptlet go inside the service() method of the servlet and everything inside jsp declaration go outside service method but inside servlet class.
if condition can only be used inside methods and request is a parameter of service method So it cannot be accessed outside service method.
Upvotes: 2