Java Server Pages: Problems With Servlets
Java Server Pages: Problems With Servlets
The Servlet itself contains the code for all aspects of the
application like
Request processing,
Business logic &
Presentation logic.
out.println("<html>");
out.println("<body>");
out.println("<b>servlet can use htmltags</b><br>");
out.println("<font color=red>");
out.println("hello shivaram");
out.println("</font></body>");
out.println("</html>");
1. Changes in the look and feel (presentation) of the
application requires the Servlet to be updated and
recompiled.
.
The “.jsp ” converted to “ java”
1. Declarations
2. Scriptlets
3. Expressions
JSP Elements
2. JSP Scripting Elements
Declarations:
A declaration tag is a piece of Java code for declaring
variables and methods.
If we declare a variable or method inside declaration tag it
means that the declaration is made inside the Servlet
class but outside the service() method.
Example
<%! int count =10; %>
JSP Elements
2. JSP Scripting Elements
Scriptlets:
1. Allows you to write Java code in JSP file.
2. JSP container moves statements in _jspservice()
method while generating Servlet from JSP.
Example:
<%
int num1=10;
int num2=40;
int num3 = num1+num2;
out.println("Scriplet Number is " +num3);
%>
JSP Elements
2. JSP Scripting Elements
Expressions
1. Evaluates the expression and send it as parameter to
out.println().
2. It allows to create expressions like arithmetic and
logical.
3. It produces scriptless JSP page.
Example:
<%= num1*num2+num3 %>
Equivalent to
out.println(num1*num2+num3);
JSP Elements
3.Actions
We can dynamically
insert a file,
reuse the bean components,
forward user to another page, etc. through JSP Actions
Unlike directives, actions are re-evaluated each time the page
is accessed.
Example
<jsp:useBean id="name“ class="demotest.DemoClass">
<jsp:include page="date.jsp“ />
<jsp:forward page="jsp_action_42.jsp" />
JSP Elements
4.Comments
request - HttpServletRequest
response - HttpServletResponse
out - JSPWriter
config - ServletConfig
exception - Throwable
session - HttpSession
application - ServletContext