Here is a short introduction to Java Server Pages or JSP. I have used simple points to describe the basics of JSP and its uses.
- JSP is a web component.
- JSP pages are compiled to Servlet automatically whereas in Servlets we need to compile to obtain the .class or java bytecodes.
- JSP Engine is a piece of Software that compiles the JSP programs.
- For JSP pages there is no need to make entry in web.xml but if required we can do so.
- Parallel development is possible in JSP.
- No need to start/stop server in case of changes made on JSP pages.
- Development time is reduced as compared to Servlets.
- Debugging is difficult in JSP.
- JSP is basically used to achieve the view part MVC (which is a design pattern).
- JSP pages are kept outside the WEB-INF folder.
Implicit Objects in JSP:
1. out JspWriter
2. request HttpServletRequest
3. response HttpServletResponse
4. application ServletContext
5. page Object
6. pageContext PageContext
7. exception JspException
8. config ServletConfig
9. session HttpSession
out.println(“I am scriptlet”);
-We can use more then one scriptlets to write java code.
– It does not execute everytime.
– We cannot use out in declaration as out is an implicit object.
– The above combination of declaration and scriptlet will produce the output as:
1 (for the first time)
2 (on refreshing the page)
3 (for the third refresh) and so on….
– This means declaration will be executed only for the first time and scriptlet is executed everytime on page refresh.
– It goes automatically to out.println() and it will display Blue Red Green
– Here we have not put ; as we do in out.println(“Blue Red Green”);
So in JSP we have basically scriptlet, declaration and expression.
– Comments in JSP can be given as:
1. Page Directive
2. Include Directive
3. Taglib Directive
e.g. of Page Directive:
– In case we want to import more files comma can be used to separate the two imports.
e.g. of Inlcude Directive:
“Wait for updates”