Java Server Pages

What is JSP?

JavaServer Pages (JSP) technology provides a simplified, fast way to create web pages that display dynamically-generated content. It is much like ASP.

JSP technology-based pages separate the page logic from its design and display. JSP technology-based pages use XML tags and scriptlets written in the Java programming language to encapsulate the logic that generates the content for the page. It passes any formatting (HTML or XML) tags directly back to the response page.

JSP technology-based pages are compiled into servlets. JSP technology-based pages may call JavaBeans technology-based components (beans) or Enterprise JavaBeans technology-based components (enterprise beans) to perform processing on the server.

"A rule of thumb is 'if you have a lot of HTML code and some 'run time variables' use JSP. If you need a lot of processing, a servlet is the best choice. Actually one can 'interleave' servlets and JSP. " Since JSP only deals with textual data, you will have to continue to use servlets when communicating with Java applets and applications.

What's the difference between JSP and ASP?
a. More security and efficiency b. Component is easier than COM c. Platform independent.

JSP Syntax

JSP Reference

JSP Web Sites

JSP FAQ
JSP information
jGuru's JSP FAQ
Understanding JSP Model 2 Architecture l
JSP Architectures
Advanced Form Processing using JSP

http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html http://www.zdnet.com/pcweek/stories/news/0,4153,410709,00.html http://developer.netscape.com/viewsource/kuslich_jsp/kuslich_jsp.html http://web2.java.sun.com/products/jsp/jsp-asp.html http://www.asptoday.com/articles/19991022.htm

Books

Professional JSP : Using JavaServer Pages, Servlets, EJB, JNDI, JDBC, XML, XSLT, and WML. 897 pages 1st edition (January 15, 2000) Wrox Press Inc; ISBN: 1861003625 ;

JSP Tutorial:

Using JSP:

If you're a Java developer already, this means you don't have to learn yet another API for creating reusable components or accessing databases.
If you're a scripter coming over from an environment like ASP, you'll be able to quickly learn JSP and carry over your Java knowledge in the future for Java applets or stand-alone applications. Aside from the similar name, JSP shares some features with Microsoft ASP. If you're already an ASP scripter, the similarities should have you up and running with JSP quickly:

Cookie:

 <% Cookie c = new Cookie("colorscheme", "blue"); 
    response.addCookie(c); %>
<% String colorscheme = ServletUtils.getCookie(request, "colorscheme"); %>

Include files:

 <% String title = "The Page Title"; %>
<%@ include file="/header.jsp" %>
Your content here
<%@ include file="/footer.jsp" %>

Looping:

 <% Enumeration e = list.elements();
while (e.hasMoreElements()) {
out.print("The next name is ");
out.println(((ISP)e.nextElement()).getName());
out.print("<br>");} %>

Call Bean:

 <jsp:useBean id="myBean" class="pack.MyBean.class" scope="page"/>
 <jsp:setProperty name="myBean" property="*"/><!--set all data-->

 
 //java bean program
 package pack;
 public class MyBean {
   String myName;
   public void setMyName(String name) {
     myName=name;
   }
   public String getMyName() {
     return myName;
   }
 }

Use Bean:

 <jsp:getProperty name="myBean" property="myName"/>
 <a href="<%= request.getContextPath() %">Home page</a>

JSP call Servlet, then Servlet call JSP

<jsp:useBean id="jspBean" class="pack.jBean" scope="request"/>
<jsp:setProperty name="jspBean" property="*" />
<jsp:forward page="/servlet/JspJSP2Servlet" /> public void doPost (HttpServletRequest request,
HttpServletResponse response) {
try {
FormBean f = (FormBean) request.getAttribute("jspBean");
f.setName("oo");
// do whatever else necessary
getServletConfig().getServletContext().
getRequestDispatcher("/jsp/jsp.jsp").forward(request,response);
} catch (Exception ex) {
. . .
}
} <jsp:useBean id="jspBean" class="pack.jBean" scope="request"/>
<jsp:getProperty name="jspBean" property="name" />
import java.sql.*;
         /* Create the connection */
         // The JDBC-ODBC Bridge driver 
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
         Connection dbCon = DriverManager.getConnection(your_dbUrl); 
         // mySQL Jdbc driver 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection dbCon = DriverManager.getConnection(
          jdbc:mysql:///test); 
         // Oracle Jdbc OCI driver 
         Class.forName("oracle.jdbc.driver.OracleDriver"); 
         Connection dbCon = DriverManager.getConnection(
          "jdbc:oracle:oci7:@mydatabase",
          "scott", "tiger"); 
         // Oracle Jdbc Thin driver 
         Class.forName("oracle.jdbc.driver.OracleDriver"); 
         Connection dbCon = DriverManager.getConnection(
          "jdbc:oracle:thin:@myhost:1521:orcl",
          "scott", "tiger");


Handling Exceptions