Saturday, April 11, 2009
1. Introduction to JSP
Java Server Pages or JSP for short is Sun's solution for developing dynamic web sites. JSP provide excellent server side scripting support for creating database driven web applications. JSP pages are high level extension of servlet and it enable the developers to embed java code in html pages. JSP files are finally compiled into a servlet by the JSP engine. Compiled servlet is used by the engine to serve the requests.
Thursday, April 9, 2009
2. INTRODUCTION TO JSP TAGS
Another important syntax element of JSP are tags.A JSP tag is somewhat like an HTML tag. JSP tags can have a "start tag", a "tag body" and an "end tag". The start and end tag both use the tag name, enclosed in < and > characters. The end starts with a / character after the < character.
Wednesday, April 8, 2009
3. Scriptlet Tag
In this tag we can insert any amount of valid java code and these codes are placed in _jspService method by the JSP engine.
a scriptlet - which means Java code within a <% .... %>
Eg : BasicCounter.jsp
<html> <body>
The Page Count is : <% out.println(Counter.getCount()); %>
</html> </body>
output
The page count is :1
a scriptlet - which means Java code within a <% .... %>
Eg : BasicCounter.jsp
<html> <body>
The Page Count is : <% out.println(Counter.getCount()); %>
</html> </body>
output
The page count is :1
Tuesday, April 7, 2009
4. Expression Tags
Expression tags automatically prints out what ever inside the Expression tags.Expressions become an arguments to the out.println()In other wors, Container takes everything inside the <%= and %> and puts it in as the argument to a statement that prints to the implicit response PrintWriter
Eg : When the Container sees this :
<%= TestCounter.getCount() %>
It turns it into this :
out.print(TestCount.getCount());
Eg : When the Container sees this :
<%= TestCounter.getCount() %>
It turns it into this :
out.print(TestCount.getCount());
Monday, April 6, 2009
5. What REALLY happens to your JSP code
Container translate your JSPcode into a Servlet.
Note : IF you want to see the generated servler code from Tomcat :
yourTomcatHomeDir/work/Catalina/yourServletName/yourWebAppName/org/appache/jsp
All Scriptlet & Expression code lands in a service() method. i.e : varibles declared in a scriptlet are always LOCAL variable.
Note : IF you want to see the generated servler code from Tomcat :
yourTomcatHomeDir/work/Catalina/yourServletName/yourWebAppName/org/appache/jsp
All Scriptlet & Expression code lands in a service() method. i.e : varibles declared in a scriptlet are always LOCAL variable.
Sunday, April 5, 2009
6. JSP Declarations
A JSP declaration always defined inside the class but outside the servise method or any other method.I.e Declaration are always ststic or instance members of the servlet class. <%!....... ; %>
E.g: BasiCounter.jsp
<html><body>
<%! int count=0 ; %>
The Page Count is now :
<%=++count%>
</html></body>
E.g: BasiCounter.jsp
<html><body>
<%! int count=0 ; %>
The Page Count is now :
<%=++count%>
</html></body>
7. JSP Implicit Objects
In JSP these implicit objects directly use instead of creating new object and using it.
API Implicit Object
JspWriter out
HttpServletRequest request
HttpServletResponse response
HttpSession session
ServletContext application
ServletConfig config
Throwable exception
PageContext pageContext
Object page
API Implicit Object
JspWriter out
HttpServletRequest request
HttpServletResponse response
HttpSession session
ServletContext application
ServletConfig config
Throwable exception
PageContext pageContext
Object page
Saturday, April 4, 2009
8. JSP Comments
<!-- HTML Commnet -->
Container just passes this straightly on to the client
<!__JSP Commnet _ _>
Container just passes this straightly on to the client
<!__JSP Commnet _ _>
Subscribe to:
Comments (Atom)