JAVA SERVER PAGES
"JSP technology is an extension of the servlet technology."
JavaServer Pages (JSP) technology enables you to mix regular, static HTML with dynamically generated content from servlets.
we write the regular HTML in the normal manner, then enclose the code for the dynamic parts in special tags, most of which start with <%and end with %>
HOW JSP WORKS
The process of making JavaServer Pages accessible on the Web is much simpler than that for servlets. all we need is a web server that support JSP pages . we save our file with .jsp extension and thats all no compiling, no packages, no classpath required.
Behind the scene our JSP page is translated into a servlet where static HTML content being printed to the output stream associated with servlet's service method.
Inside a JSP Page :
Aside from the regular HTML, there are three main types of JSP constructs that you embed in a page: scripting elements, directives, and actions.
SCRIPTING ELEMENTS : java code that will become part of resultant servlet.
DIRECTIVES : control the overall structure of servlet.
ACTION : control the behaviour of JSP engine.
SCRIPTING ELEMENTS
- EXPRESSIONS : which are evaluated and then inserted into servlet's output . General form : <%= %> Alternate XML syntax : <jsp : expression> Java Expression </jsp : expression>
- SCRIPTLETS : which are inserted into servlet's _service method. General form: <% %> Alternate XML syntax : <jsp : scriptlets> code </jsp : scriptlets>
- DECLARATION : which are inserted into body of servlet's class outside any method. General form: <%! %> Alternate XML syntax : <jsp : declaration> code </jsp : declaration>
Static HTML inside a JSP page is called Template Text.
JSP Comments are in the form <%-- jsp comment --%>
A simplest example of
EXAMPLE :
ScriptingElement.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>Insert title here</title>
</head>
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<%-- expression example --%>
current date and time is :
<%= new java.util.Date() %>
<hr>
<%= request.getRemoteHost() %>
<hr>
<%= request.getRemoteHost() %>
<hr>
<%-- delaration example --%>
<%! int count =1; %>
<%-- scriptlet example --%>
<% count++;
out.println(count); %>
out.println(count); %>
<hr>
</body>
</html>
OUTPUT
OUTPUT
No comments:
Post a Comment