జేస్ప్ 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)
(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
- Allows to separate presentation logic from business logic
- Supports tags based programming
- Gives 9 implicit objects
- Suitable for both java and non-java programmers
- Allows us to use all features of servlets
- Designed based on page compilation principle, so every jsp will be translated to a equalent servlet
- Exception handling is optional ,but allows to configure error pages
- Gives support for EL(Expression language), JSTL tags to make jsp as java code less jsp
- Gives built-in tags and also allows us to use 3rd party supplied tags
- Easy to learn & apply
- Servlet Container /Servlet Engine is required to execute Servlet components
- JSP Container /JSP Engine is required to execute JSP components
- 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
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
(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), exception1.)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
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
a.)jsp container name: Jasper(jasper.jar)
servletcontainer name: Catalina(catalina.jar)
b.)JSP page compiler: jspC
Difference between HTML & JSP:
HTML:
- Client side web technology
- HTML interpreter is required to execute html code
- Given by W3C
- Tags and attributes are not case-sensitive
- Not a strictly typed language
- Doesn't allow to place java code Note: .html file is called html component /page
JSP:
- Server side technology
- JspContainer/ Engine is required to execute jsp pages/components
- Given by SUN MS(oracle crop)
- Case-Sensitive
- Strictly typed language
- Allows to place java code Note: .jsp file is called jsp component /page
Structure of JSP code:
- Java code placed in jsp tags is called script code
- Jsp page/component dynamic web page
- The static content of jsp page generated web page comes because of template text like fixed labels
- 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- E:\JspApp
- |-->WEB-INF
- |--> web.xml
- |-->first.jsp
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
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
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
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
- JspApp1
- |-->WEB-INF
- |-->pages
- |-->first.jsp
- |-->web.xml
web.xml
- <web-app>
- <servlet>
- <servlet-name>one</servlet-name>
- <jsp-file>/WEB-INF/pages/first.jsp</jsp-file>
- </servlet>
- <servlet-mapping>
- <servlet-name>one</servlet-name>
- <url-pattern>/test1.c</url-pattern>
- </servlet-mapping>
- </web-app>
Comments
Post a Comment