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? JSP Web Sites
Books
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.
Cookie: <% Cookie c = new Cookie("colorscheme", "blue"); response.addCookie(c); %> Include files: <% String title = "The Page Title"; %> Looping: <% Enumeration e = list.elements(); 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"/> 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");
|