Escolar Documentos
Profissional Documentos
Cultura Documentos
And if you dont write java code ,then what do you write?
How does it translate into Java code?
Six different kinds of JSP elements each with its own purpose and unique syntax.
How ,why and what to write in your JSP?
What not to write in your JSP.
JSP is just a servlet : MyJSP.jsp
MyJSP_jsp servlet
MyJSP_jsp.java MyJSP_jsp.class
Where does each part of your jsp file end up in the servlet source code?
Do you have access to the servletness of your JSP page?
For example does your JSP have the concept of ServletConfig or ServletContext?
What are the types of elements you can put in a JSP?
Whats the syntax of the different elements in a JSP?
Whats the lifecycle of a JSP and can you step into the middle of it?
How do the different elements in JSP interact in the final servlet?
What are scriptlets?
Using scriptlets you can put regular, old java code in a jsp
Scriptlet : <% out.println(Counter.getCount()); %>
What are directives?
Use fully qualified class name or use page directive to import packages.
<%@ page import =foo.* ,java.util.* %.>
Implicit Objects
With implicit objects you can write a JSP knowing that your code is going to be part of
servlet
All of the implicit objects map to something in the Servlet/JSP API.
E.g request object is a reference to the HttpServletRequest object passed to service
method by the container
Implicit objects
API
Implicit Objects
JspWriter
HttpServletRequest
HttpServletresponse
HttpSession
ServletContext
ServletConfig
Throwable
PageContext
Object
out
request
response
session
application
config
exception
pagecontext
page
Comments
//this is a comment
Unless this is within a scriptlet or declaration tag ,youll end up displaying this to the
client as part of response.
The container those 2 tags are template text.
2 different types of comments ins JSP :
i.HTML comment : <!-- HTML comment -->
the container passes this straight on to the client where the browser interprets it as a
comment
these are comments that stay as part of response
ii.JSP Comment : <%-- JSP Comment --%>
these are for page developers like java comments in java source file
theryre stripped out of translated page
these are comments about wat u r doing.
jspInit()
It is called from init() of generated servlet,so by the time this method runs there is a
ServletConfig and ServletContext available to the servlet.
So u can call getServletConfig() and getServletContext() from within the jspInit()
method.
What are the 4 implicit objects used in a JSP to get and set attributes?
application,request,session,pagecontext
all 4 have on emethod for setting attribute
application.setAttribute(foo,barObj);
But what is the other way to get and set attributes in a JSP at any scope?
Using the pageContext implicit object
The methods that work with other scopes take an int argument to indicate the scope.
Although the attribute access methods come from JspContext,youll find the constants for
the scopes in the PageContext class.
The 3 directives
1. Page directive : defines page specific properties
<%@ page import=foo.* session=false %>
a. character encoding for page
b. content type for this pages response.
c. Whether this page should have an implicit session object
Ignoring EL
Why ignore : same reason as assert keyword was added with java 5
So previously if there was ${} then it wud give problem
1. Using DD
<web-app>
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</ el-ignored >
</jsp-property-group>
<jsp-config>
2. Using page directive
<%@ page isElIgnored=true %>