Saturday, March 28, 2015

JSP web application dvelopment

Developing applications in JSP


Java Server Pages formally known as (JSP) is a great platform for developing web pages which support dynamic content that helps developers inserting java code in HTML pages by using genuine JSP tags, most of which start with <% and terminates with %>.

While developing application Java Server Page tags are used for a variety of purposes, they areas retrieving information from database or registering user preferences, accessing Java Beans components, passing control between pages and sharing information between requests, pages etc.

Java Server Pages (JSP)  has components as a category of Java Servlet which is designed to fulfill the role of a user interface for a Java web application. Web developers write JSP's as text files that combine HTML or XHTML code, XML elements, and embedded JSP actions and commands.
Because of JSP, you can collect input data from users through web page forms, present records from a database or another source, and create web pages dynamically.


Why use JSP  in your application?


JavaServer Pages often serve the same purpose as programs implemented using the Common Gateway Interface (CGI). But JSP offer several advantages in comparison with the CGI.
Performance is obviously better because JSP allows embedding Dynamic Elements in HTML Pages itself instead of having a different CGI files.

Key points for JSP use in your application :
  1. Java Server Pages are always compiled before it's processed by the server .
  2. Java Server Pages are built on top of the Java Servlets API, so like Servlets, JSP also has access to all the powerful Enterprise Java APIs, including JDBC, JNDI, EJB, JAXP etc.
  3. Java Server Pages  can be used in combination with servlets that handle the business logic, the model supported by Java servlet template engines.
  4. Finally, Java Server Pages is an integral part of JavaEE, a complete platform for enterprise class applications. This means that Java Server Pages can play a part in the simplest applications to the most complex and demanding.


JSP File (index.jsp)

 <%  
  String theSharedObject = "JSP is cool";  
 application.setAttribute("message", theSharedObject);  
 %>  
 <!DOCTYPE html>  
 <html>  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
 <title>Nirajan Ghimirey's Workshop</title>  
 </head>  
 <p>About Nirajan Ghimirey's Workshop</p>  
   Click <a href="application.jsp">here</a> to see this in action.  
 </body>  
 </html>  

JSP File (application.jsp)
 <%  
   // getAttribute() returns a java.lang.Object, so need to cast  
   String theSharedObject = (String) application.getAttribute("message");  
 %>  
 <!DOCTYPE html>  
 <html>  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  
 <title>Nirajan Ghimirey's Workshop</title>  
 </head>  
 <body>  
 <h2> This information from <i>application</i>object by another page.</h2>  
 <p>nirajanghimireyworkshop.blogspot.com is one of the best idea and a website which contains tutorials about web designing, web development, programming,and other skills.</p>  
 <p>  
       The message is <b><%= theSharedObject%></b>  
 </p>  
 </body>  
 </html>  


No comments:

Post a Comment