Skip to main content

Introduction

జేస్ప్  JSP जसप 

(Q)Why did sun micro system given jsp technology even though it is already having servlet technology?


a.) In the initial days of servlet launching the programmers didn't liked servlet because of there is no tag based programming in servlet and strong java knowledge is required to work with servlet

b.) The programmers have rejected servlet though it is having good features. To overcome these problem sun microsystem had given jsp having all the features of servlet and having support of tag based programming

c.) JSP is suitable for both java and non java programmers

d.) In the initial days of jsp the programmers have used JSP as complete alternate to servlet and asp, but in the modern development the programmers are using servlet , jsp technologies together in the web application development(mvc1,mvc2 architecture)

Difference between Servlet(s) & JSP(j)

(s)Strong java knowledge is required
(j)Not required

(s)Suitable for only java programmers
(j)suitable for java and non-java programmers

(s)Doesn't supports tag based programming
(j)supports

(s)Makes the programmers to mix up business logic(java code) and presentation logic(html code)
    E.g pw.println("<b>hi</b>")
(j)Allows to separate html code(presentation logic) from java code(business logic)

(s)Placing html code in servlet component is error prone process(possibility of doing mistakes is more)
(j)Is not a error prone process

(s)Exception handling is mandatory
(j)Optional

(s)No implicit objects support but gives container created objects
(j)Gives 9 implicit objects

(s)Servlet Configuration in web.xml file is mandatory
(j)Optional

(s)Modifications done in servlet component reflect only after recompilation of servlet and reloading of web application
(j)Such things are not required

Note:

(1)The objects that are not created by underlying jvm/container without writing additional code are called Implicit objects

(2)The objects that are created by underlying container / jvm but needs to write some additional code to access them are just called container/jvm created objects(req,res, servletconfig...etc )
a.) Main(-) method string args[], catch blocks, Exception objects are jvm created objects but not implicit objects
b.) super/this operators/keywords are implicit objects/references because we can use them directly in our applicatios without writing any additional code

JSP Features


  1. Allows to separate presentation logic from business logic
  2. Supports tags based programming
  3. Gives 9 implicit objects
  4. Suitable for both java and non-java programmers
  5. Allows us to use all features of servlets
  6. Designed based on page compilation principle, so every jsp will be translated to a equalent servlet
  7. Exception handling is optional ,but allows to configure error pages
  8. Gives support for EL(Expression language), JSTL tags to make jsp as java code less jsp
  9. Gives built-in tags and also allows us to use 3rd party supplied tags
  10. Easy to learn & apply
  11. Servlet Container /Servlet Engine is required to execute Servlet components
  12. JSP Container /JSP Engine is required to execute JSP components 
  13. JSP container gives built in jsp PageCompiler to convert jsp components into an equalent servlet component
In Tomcat server:
a.)jsp container name: Jasper(jasper.jar)
servletcontainer name: Catalina(catalina.jar)
b.)JSP page compiler: jspC

Difference between HTML & JSP:

HTML:


  1. Client side web technology
  2. HTML interpreter is required to execute html code
  3. Given by W3C
  4. Tags and attributes are not case-sensitive
  5. Not a strictly typed language
  6. Doesn't allow to place java code
  7. Note: .html file is called html component /page

JSP:


  1. Server side technology
  2. JspContainer/ Engine is required to execute jsp pages/components
  3. Given by SUN MS(oracle crop)
  4. Case-Sensitive
  5. Strictly typed language
  6. Allows to place java code
  7. Note: .jsp file is called jsp component /page
Structure of JSP code:


  1. Java code placed in jsp tags is called script code
  2. Jsp page/component dynamic web page
  3. The static content of jsp page generated web page comes because of template text like fixed labels
  4. The dynamic content of jsp page generated web page comes because of java code placed in scriptlet

Procedure to develop jsp component /page based web application

a.)Create deployment directory structure
  1. E:\JspApp 
  2. |-->WEB-INF 
  3. |--> web.xml 
  4. |-->first.jsp 
Note: first.jsp configuration in web.xml file is not required because it is placed outside the WEB-INF folder(Available in public area)

b.)start the tomcat server

c.)Deploy the application
    Copy E:\JspApp to <tomcat_home>\web apps folder

d.)Test the application
    In browser http:\\localhost:2525\JspApp\first.jsp

e.)While developing and executing jsp we need not to add any jar files to the class path or build path because there is no need of compiling jsp outside the server

f.)The jsp page compiler that is there in jsp container takes care of jsp page compilation and generates jsp equivalent servlet


JES(Java Equivalent Servlet):

     In tomcat server the jes class source code ,compiled code for first.jsp comes as first_jsp.java and first_jsp.class in tomcat home\work\catalina\JspApp\org\apache\jsp folder

(Q)How many types of objects used in jsp programming ?
1.)They are 2 types
    a.)Explicit objects(created by the programmers)
       <%java.util.Date d=new java.util.Date();%>
    b.)Implicit objects /reference variables(created in JES class directory)

2.) 9 implicit objects:
    out,page, PageContext, request, response, session, config(ServletConfig object), application(ServletContext object), exception

About JES class in Tomcat server

1.)It is HttpServlet class based servlet component
2.)Gives 3 imp methods
_jspInit(), _jspDestroy(), _jspService(req,res) ("_" indicates container generated methods)
3.)Template Text, code placed in scriptlet goes to _jspService()
4.)_jspService(-,-) method contains implicit objects creates logic and exception handling logic

JES class Hierarchy in tomcat server


1.)If you place jsp components outside the WEB-INF folder, the following limitations can occur
   a.)Based on the url info(.jsp extension) end user/hacker may know the technology of the website
   b.)If JSP component is displaying the request attribute values given by servlet component, the direct request to jsp component may display ugly values.

Note: To overcome these problem stop direct request to jsp component by placing that jsp component inside the WEB-INF folder(private area)

2.)To access the jsp component by generating the request even though it is placed in WEB-INF folder we need configure jsp component in web.xml file having url-pattern
  1. JspApp1
  2. |-->WEB-INF
  3.        |-->pages
  4.               |-->first.jsp
  5.        |-->web.xml

web.xml

  1. <web-app>
  2. <servlet>
  3.   <servlet-name>one</servlet-name>
  4.   <jsp-file>/WEB-INF/pages/first.jsp</jsp-file>
  5. </servlet>
  6. <servlet-mapping>
  7.   <servlet-name>one</servlet-name>
  8.   <url-pattern>/test1.c</url-pattern>
  9. </servlet-mapping>
  10. </web-app>

Comments

Popular posts from this blog

JSP Comments

Comments in JSP:- -->Compiler /Interpreter doesn't take commented code for compilation /Interpretation, so the commented code doesn't participate in execution JSP supports 3 types of comments:- a.)HTML comments /Template text comments/ Output comments Syn :- <!---text---> -->Recognized by html interpreter of browser b.)JSP comments /Hidden comments Syn :- <%--text--%> -->JSP page compiler recognize these comments c.)Java comments /Scripting comments Syn :- //-->For single line /*-- -----*/-->For multiple line -->Java compiler(java) recognize these comments -->In Eclipse IDE JES class for first.jsp comes in our(workspace)folder/.metadata/.plugins/.org eclipse Comments (1)JSP comment<%--%> (2)Java comment(// or /*--*/) (3)HTML comments(<!---> JES Source Code (1)No (2)Yes (3)Yes In JES compiled code (1)No (2)No (3)Yes In the code going to browser (1)No (2)No (3)Yes Output (1)No (2)No (3)No -->Jsp comments are not visible in any phase...

Scripting Tags

JSP Tags/ Elements (1)Scriptlet     Standard syn:-         <%.........%>     xml syn:-        <jsp:scriptlet>...</jsp:scriptlet> Note: All scripting tags allows us to place script code(java code) 1.)The code placed in scriptlet go to _jspService(-,-) of JES class 2.)In a jsp page we can have zero or more scriptlets 3.)We place request processing logics in scriptlets 4.)Variables declared in scriptlets becomes the local variables in _jspService(-,-) of JES class in first.jsp In first.jsp: <% int a=10;  out.println("square:"+(a*a));%> In first_jsp.java(JES): public class first_jsp extends..{     public void _jspService(-,-){        int t=30;        out.println(“Square:”+(t*t));     }  } The code placed in scriptlet can use implicit objects of jsp because implicit objects and the code placed scriptlet goes to _jspService(-...

Project Architecture's

1.) Functional flow/ Architecture a.) Only for 6+/7+years b.) Explain the flow of process/business 2.) Technical Flow/Architecture a.) Upto 5+ years b.) Explain technologies /components that are involved in the project Servlet & JSP Project Architecture:- 1.)What is need of Business Deligate to convert VO class object to DTO class object ? a.) If Business Deligate is not there servlet component directly prepares DTO class object by receiving and translating form data and passes to service class, if service class excepts certain input in other format like numeric employee number as string employee number then we need to modify servlet component code i.e For the changes that happened in business tier service component we have to modify servlet component of presentation tier b.) If Business Deligate is taken then it gets original form data as VO class object having string inputs and converts VO class object to DTO class object to pass to service class c.) If service class excepts ...