Xelian
Xelian

Reputation: 17208

Why we can not access request from jsp declarations?

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?

enter image description here

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

Answers (1)

navintb
navintb

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

Related Questions