0

We often do the following inside the scriptlet:

<%
   request.getCookies();
%>

Can anyone tell me, what is request here? I know it represents HttpServletRequest but I haven't declared it. I just do not understand this.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
saplingPro
  • 20,769
  • 53
  • 137
  • 195

1 Answers1

3

request is a variable of type HttpServletRequest that is declared and initialized for you in the code generated by the servlet container when the JSP code is transformed into a Servlet class and compiled, it also known as one of implicit objects in JSP.

Note that using scriptlets in JSP is bad practice for years. You should learn JSP EL, the JSTL, and choose an MVC framework that allows separating the Java code for the pure markup-generation code.

Prakash K
  • 11,669
  • 6
  • 51
  • 109
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • The JSP EL is the JSP expression language. It's a language that you use inside JSPs. You can't skip JSPs. – JB Nizet Jul 27 '12 at 10:40
  • Yes, forget they exist. They shouldn't be used. – JB Nizet Jul 27 '12 at 10:44
  • Related: http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files/3180202#3180202 and http://stackoverflow.com/tags/el/info – BalusC Jul 27 '12 at 16:27