��������� � ������������ Web-������������ - Java Server Pages

 

� ������� �����, 2000

http://www.nakov.com

 

����� �� ��� ����� �� � ���������� 1-2 ������, ������ ����� ���� �� ���������� �� �������, JAVA � ���-����� ������������� ���������� � ������������ ������. ����� �� ��� ����� ����, �� ���� ������� ���������� ������ ����� ���������� �������� �� ���������� �� ���������� � ������ �� ����������� ������ � �������� ����� � ������ �� ������ �� � ��������� ����� �� ���� ���. ��� �� �� �������� �� ������, �� �� ������� ���� ��� ������� �� ������������, ����� ��� �� ���-��������� � XML, Enterprise Java Beans, Java Server Pages, Oracle, SQL Server. �� ���� �� ���� �� ORACLE (���������� ����� ������� Microsoft �� ��������� ����� ����� � �������) ������� �� ���� ������ e-business ��� �� out-of-business�. �� ���� ������� ����� ����, �� WEB-������������ �� �� �� ��� ��-������ �������� ���� �������� ������. ��� ���� � ���������� ������ ������ �� �� �������� � ���� �� ���-��������� ���������� �� �������� ������������ � Java Server Pages (JSP), ����� � ������� � ����� ���. ���������� ������ �� ����� ���������� ����������� �� �������� �JAVA �������� � ��������� � WEB-��������������, ����������� � ���� 5/2000 �� ��. PC Magazine/Bulgaria, ���� �� �������� ������, ����� �� �� ���������� � WEB-�������������� � JAVA, �� �������� ����� ���.

���� ���� �� �������� ��� ����� ������ � WEB-�������������� � JAVA. ������ e-business-� �� ����� ������� �� WEB-���������� ������������� �������, �� ����� �������� �� ������������ �� ��������� �� ��������� ���������� HTML-��������. � ���� �� ������� ���� �� ���� ���������� � ���������� ������ ������� ��������� �� ��������� �� ��������� HTML, �� ��������, �� �� ����� �� �� �������� �� ��� ���� � ���������� �� ��� HTML �������� � �������� �� ��������� �� Server Side ���������� /������/ (������� �� Perl, Bash, C++, Java � �.�.) � ���������� �� ��������� ���������� � �������� �� ��������� �� ��������� ��� (�� PHP, Active Server Pages /ASP/, Java Server Pages /JSP/ ��� Cold Fusion) ����� � ����� HTML ��������, ����� �� ������������ �� �������. �� �� ����� �� ������� JSP ������������, �� ����� ����� �� �� �� ��������� � JAVA ����������, ������ ����� �� �������� ���� �����, ���� ��� ���������� �� ����� ����� ��������. JAVA ��������� ������������ �������� �� JAVA, ����� �� ��������� �� ������� ��� ���������� �� ������ �� ������, ��������� �� WEB-�������� �� �������. ���� JAVA �������� �� ������ �� ���� ��� ������� �����, �������� ���� .class ������� ��� .jar �����. �� ������ �����������, ��������� �� ������� � � ���������� �� ��� ����� ������� ��������� ��������� HTML ��������. � ����� �� ��������, �� ��������, �� ���������� ����� ���� ���� � ��������, ����� JAVA ���� ���� ���� � JavaScript.

�� �� ������ �� ���������� JAVA �������� � JSP �� � ��������� WEB-������ ��� Application-������, ����� �� ��������. ��� ���������� ����� �� ���������� JAVA �������� ������� (���� JAVA Web Server �� Sun ��� Weblogic Application Server), ��� ����� ����� Application ������� � �������� JAVA ��������� (���� ORACLE Application Server � IBM WebSphere Application Server), ���� �� ��� ����� �� ����������� ���� ������������, �� �� ��������� ���-����������� WEB-������� Apache � IIS (MS Internet Information Server) ��� ��� �� ���������� ��������� ����������. ���� �� ���-��������� ������� �� ����������� �� Servlet/JSP ������������ � Apache � Tomcat (http://jakarta.apache.org). �� ����������, ����� ����� �� �� ��������� � ����, �� ��������, �� ������������� �� Tomcat ������ �� � ����� ������ �� ���� ��� ���� � � ����� �������� �����, ����� �� ������� �� UNIX � JAVA �� ����� �� �� �������. ���� � ���������� ������ �� ���-��������������� WEB-������ � ����� Apache (� ��� 60% ������� ��� � http://www.apache.org) Tomcat �� ���� ���� ������� ���������� ����� �������� Perl, ������ �� ����� �� ����� � Tomcat � ����������� �� ����� ������...

������ ���������� Servlet/JSP ��������� ������, ���� ����� �� �������� ������. �� ���������� ��������� �� �������� �� ����������. ��� ����� ��������� �������� ������� class ��������� �� �������� � �� ������� � ������� ���� ������ ��� ���, ����� �� ���������� � ������� �� ���� ���� �� ���������. ��� �������� ���������, ����� �� �� ���� ���������� � �������� ���� �� ���������. ���� ������ ������ ������� �����. (������� ����� ��, ������� ��, ���� �� ������� ����� ��������, �� �� ������ �� ������������� ���� ���� ���������� �� � �������. � �������� ����� ���� ������ �� �JAVA-�� ���� ������. ��� ���� �� �, ����� �� �� � ������� �� ���� ����, �� ����� 512 MB RAM � Katmai �� 800 Mhz. �� ����� �� ������ ������ ����� �������� ��� ���������. ���� �, �� ����������, ���� �������� �� JAVA �� ����� ��-����� �� �������� ����������� ����������, �� Sun �� ��������� ������ ��������, �� �� �� �������� �� ������, � ����� �� ���������, �� ������. �� ���� �� ���, ������� ��, ����� �������, �� �� �� �� ����������� �� ������...).

���� ����� ���� ����� �� JSP � ����� � �������� �� ��� ����������. JSP (Java Server Pages) � ���������� �� ��������� �� ��������� ���, ������� �� JAVA � HTML ���������. ������ � ������ � �� �� �� �������� ��� HTML �������� (����� � ��� ����������), � �� �� ������� ���� ������� ��������� ���������. ���� ��������� ���������� �������� �� JAVA �����������, ������ ��� ���� �� ������ �� �� ����� ������ �� ���������� �� HTML ���������, ����� �� � ���� ����� ������, ������� ��� ������ ���������� �� �������� �����. ������ ����� ����: ����� �� ���-��������� HTML � ������� HTML �������� � ��������, �� �� ������ ������� ��������� ����������. � ���� ������ �������� ��������� ��� �<%�� � ���� �� ����� �� JAVA. �� ��������� �� ����� � HTML ��������� ���������� ������ out.println(String), a �� ���������� �� ���������� �� �������� ��������� ���������� ������ request.getParameter(String param_name). ������ ������� � JAVA ����, ��������� JAVA ���� � �%>� � ������������ � HTML-a. ��� ������ �� ������ �� ���� �������� �������� �� �������, ��������� JAVA ���� � ����, �������� �� � ��������� �� �������� ���������� � ����� �� ������� ���� ������������ �������� ��� ��� �� ���� HTML. �, ����, ������� �� �� � ������ ����, �� ������ �������� ����. �� �������� �� ��������� �� ��-������ ������� �����������, ��������� JSP ��������� (���-����� ������� � ���������� .jsp ��� .jhtml) �� ���������� ������������� �� JAVA �������� (������� � ���������� .java), � ����� �� .class �������. �� ����� �������� �������� ��������� JSP ����������, � ����� �������� �� HTML ��������� �������� �� JAVA (������� �������), � ���� ���� � ��������� ��� ����������� ���������� �� Sun javac. JSP ������������ �������� ���� ���������� ������ �� JAVA ������� � ������ ������ � ���� �� ����� ��� �xxx� �� HTML ���� �� ���� ��� �� ���� out.println(�xxx�), � ����� ���, ����� � JAVA ���, ������ �� ������ 1 ��� 1. ���� �� �������� ���� ��� �� JAVA �������, ����� ����������� �� JSP ���������. � ������ ������ ����� JSP ��������, ����� ��� ����� ������ �� ��� ����� �� ������� � �������� 100% ��������� HTML.

��������� ��������� �� JSP ������������. ���� ���� � ����� � ��������. ��� ���� ����� �������� JSP ������ (date_time.jsp), ����� ������ ��� ���� � ����� ���� � � ������� �� ������������ ��:

<%@ page import="java.util.*;" %>

<HTML>��

� <TITLE>JSP example - very simple Date and Time script</TITLE>

� Today is <I>� <% out.println(new Date()); %>� </I>

</HTML>

���� ���� �� ������� � ����������� ���������� �� ������� � �� �������� �� Internet Explorer ���������� ������� ��������:

���������� ��������� �� ����������� HTML �������� �� �� ������ ��� ���� ���� <%@ page import="java.util.*;" %> �� �������� �������� java.util.*, �� �� ���� ��-������ �� �� ������ java.utils.Date(). ���� ���� � out.println() �� ������� ������ � ����, ����� �� ������ �� ����������� �� JAVA ����� � ���� ��������� �� ����� �� ����� Date.

����������� ���� ���� ����� ���� ����� ����� � ��� �� ������ �����������. �� �� �������� ���� ������ �������. �� �� ������ JSP ���������, ����� ��� ��������� ��� ��������� �� ������� ����� � ���� �� ��������� �� ��� �� ����������. ��� submit-���� �� ������� �� �� ���� ������ ��������� � ��������� name=<���_��_����������>. � ���� ������ �� �� ���������� �����������, ����� �� � ����� �����, � ��� ��� �� � ����� ����, �� �� �� ����. ��� ��� �������� ���� �������� ������� (tvoita_mamka.jsp) :

<HTML>

�� <TITLE> JSP example - Hello tvoita mamka </TITLE>

<% String name = request.getParameter("name");

�� if (name == null) { %>���

����� <FORM METHOD=GET ACTION="/tvoita_mamka.jsp">

����� Please enter your name: <BR>

����� <INPUT TYPE=TEXT NAME="name">

����� <INPUT TYPE=SUBMIT VALUE="OK">

����� </FORM>

<% } else if (name.trim().length() > 0)

������ out.println("Hello <B>" + name + "</B> :)).");

���� else out.println("Tvoita mamka, daj si imeto be!");

%>

</HTML>

��� ���������� ��� ��������� �� �������� ��������:

��� ���������� � ��������� �Svetlin Nakov� �� ��������:

����� ������� ������������ �� ����������� (������, ����� ���� ������ �� ������� �?� � URL-��) �� ����� ��������� ����� � � ��������� request.getParameter(String param_name), ����� ����� ������� ��������� ��� ��� �� �������� ��� ��� null, ��� ��� �� ���������. ����, ����� ��� ����������, � �������� �� ����� ������� � ������������ ���������� �� ���������� ��� ������������ �� �����������. ��� �� ������ � �������� ��������� (���� �� �������� � ���������� ������), �� ����������� �� ���������� ������� ���:

String param = request.getParameter(�parameter_name�);

try { param = java.net.URLDecoder.decode(param);

} catch (Exception e) { e.printStackTrace(); }

����������� ����� �������� � ����������� ������ �� ����������, ���������� �� ��������� ��� � HTML ��������� �� � ������ �� �� �����. � ������������ ��������� ���������� � �������� ���� ���������� ���������� ����� ��� ������� �� ������������. ������, ������ �� ������ ����� ����� ������, ��� ������ �� �� ������� ��������� �� ����� ������, ����� ���� ����� �� ������� ����������, � ���� ���� �� ������ �� �� ����������. ���� � ������������ ������� ����� �� ������ �� ����� ���� ����� ���� � ��� ������. JSP �� ���� ���������� �� ����������� �� ����. ������������ ������ � �������� �� �� ������ � ������� ����� (� ���� ����), � �� �� �� ������ � ����, ����� �� ����� �� ���������� ������ ��� � �������������� �������� �� �����. �� ���� ����� WEB-������� �� ��� ������� �� ������� ������������� ����, ���� �������� ������������� ���������� �� ����������� ������ �� ��������� �� ������������ � ��������� �� ����������� ����������. � ����� ������ ���� ������ �� JAVA Beans, �����, ����� �� ����� ���� �����, �� ����� ��������� ����� �� JSP ���������. ����� ������ �� �������, �� JAVA Bean-� � ������ ���� JAVA ����, ����� ��� ������� �������� ������ � ����� �� ���� getXXXsetXXX �� ������ �� ����� ������, ������ � �����, ���� ���� ������ �� ������� Property-��. ������� �� ���� ����������� �� bean � ����� �������, �� ������ ���� �� �� ����� ������. ������������ �� bean-��� �� JSP �������� ����� ����������� ���� <jsp:useBean id=name scope=scope class=bean_class_name>, ����� ������� ��� ����� �� ��������� ���� � �� ���� �������� ��� name. ���� ����� � ����� � ������� �� ��������� ���������� � JAVA, ��� ���� �� � �������� ���� name = new bean_class_name() � �� �������� �� ����������� �����, �� ����� �� ��������� �������� � JAVA.

����������� ����, �� �� ����������� ��������� �� JSP/Beans ������������, �� �� �������� ���� ����� ��-������ ������ �� ����������. ���� ��� �� ���� �� ������� ��� �� ������� bean-��� �� JSP, �� ���� � ��� �� ����������� ������ �� ���� �� ����� ���� WEB ���� �� �������� JSP. �� �� ����������, �� ����� ���� ���� �� ������, ����� � �������� � ��������� emails � ORACLE ���� �� �����. ��������� emails �� ������ �� �������� id, area, subject, sender, problem, solution, ������ ����� ����� �� ��� �������� ����� id � ������� ���� ������, ����� �� ������ �� ���������� ������. ������ ������ � �� ������� JSP ������, ����� �� ������� ����� �� ����� �� ������� ������������ (��������) �� ���� ����� ��� ��� �� ��������. �� �������� �� ���� ������, ����������� �� �� ������, ����� ����� ���������� �� ���� �� ������ ���� WEB-����������� ������������� ������� �� ������ � ������������ �� �����. ��� ���� �������� ����� ���� ������ � ��� �� ����������� ������������, ��� �� ������ ����� �� ���� ����������� �� �� ��������� � �������� � JSP ������������. �� �����������, �� ����� ������� ���� ������� SearchBean, ����� ��� ����� �� ��������� �� ����� �� ������ ����� � ������ �� ������ �� �������� �� ���� �����. ������ ����� ����� �� ������� �������, ����� ������� ������ �� ������� ����� (Search.jsp) :

<%@ page import="SearchBean" %>

<!-- SearchBean should be in the JSP Servlet Engine's CLASSPATH -->

 

<HTML>

<TITLE> JSP, BEANS and ODBC example </TITLE>

<BODY>

 

<jsp:useBean id="record" class="SearchBean" scope="application">

</jsp:useBean>

 

<%� String id = request.getParameter("id");

��� record.loadRecordFromDatabase(id);���� %>

 

<center>

<table width=100% border=1>

� <tr> <td> Area:���� </td> <td> <%= record.getArea()���� %> </td> </tr>

� <tr> <td> Subject:� </td> <td> <%= record.getSubject()� %> </td> </tr>

� <tr> <td> Sender:�� </td> <td> <%= record.getSender()�� %> </td> </tr>

� <tr> <td> Problem:� </td> <td> <%= record.getProblem()� %> </td> </tr>

� <tr> <td> Solution: </td> <td> <%= record.getSolution() %> </td> </tr>

</table>

</center>

 

</BODY> </HTML>

����� ���� �� ����, � �������� �� ������� ���� ���� �<jsp:useBean � >� �� ������� ����� �� ����� SearchBean ������� record. ���� ���� �������� ����� �� ���������� �� ��������� ���������� �� ���������� id � ���� ������ �� ��������� �� ������ � ����� id �� ������ �����. ���� ���� �������� ������ �������� �� ����������� �� HTML ����� � ������ �� ����� ����� � �������� �, ��� ���� �������� �� ������ record �� ��������� �� ����������� ������ �� ���������� �� ������ �����. �� �������� �� ��������� �� ����������� �� �����, ����� ����� String, �� ������ ���� �<%=�. ����� ������� � JSP ��������� ���� ������ JAVA ��� � ������ �������� � ���� ������. WEB-�������� ���� �� ������� ��������� ������ ���, ��� �� �� ���������� �� ���� ��� �� �������� �������. �� ���� � ����� ���� ��� �� Property-���� �� ���������� bean, ����� ������ �� �� ������� � ��� �� ������������ bean-�. ������������, �� ���� ������ ���� ������ �� ������ ���������� bean (SearchBean.java) ��� ������ �� �� �������� � ���������� �� ������� ��� �� �������, ����� �� �� ��������. ���������� � ���� �� ������� ����� ����� �� ������� ���������. � ���� �� ������ ������������� �� ������������ � ����� 2 ������� ���������� ����� � ��������� (JSP ���������, �������� �� WEB-���������) � ������ ������ (JAVA bean-a, ������� �� �����������). �� ��������� � ����� bean (SearchBean.java) :

import java.sql.*;

 

public class SearchBean {

 

� private static Connection con;

� private String area, sender, subject, problem, solution;

 

� // Establish database connection

� private static void connectToDatabase() {

��� try {

����� if (con != null)

������� if (!(con.isClosed())) return;� // Already connected

����� Class.forName("oracle.jdbc.driver.OracleDriver");

����� con = DriverManager.getConnection(

����������� "jdbc:oracle:thin:@192.168.20.111:1521:MYORACLE",

����������� "mente", "mente123");

��� } catch (Exception e)

������ { e.printStackTrace(); }� // Can't connect to database

� }

 

� // Retrieve the record with given id from the database

� public void loadRecordFromDatabase(String id) {

��� connectToDatabase();

��� String query = "SELECT area, subject, sender, problem," +

������������������ "solution FROM emails WHERE id=" + id;

��� area = subject = problem = solution = "";

��� try {

����� ResultSet res = con.createStatement().executeQuery(query);

����� if (res.next()) {

������� area��� = res.getString("area");

������� subject = res.getString("subject");

������� sender� = res.getString("sender");

������� problem = res.getString("problem");

������� solution= res.getString("solution");

����� }

��� } catch (Exception e) { e.printStackTrace(); }

� }

 

� public String getArea() { return area; }

� public String getSubject() { return subject; }

� public String getSender() { return sender; }

� public String getProblem() { return problem; }

� public String getSolution() { return solution; }

}

��� ����������� �� ������ loadRecordFromDatabase(String id) �� ��������� ���� ��� �������� ������ � ������ � ��� ��� �� �������� ��, � ��� ���� �� ������� ����. ���� ���� �� ��������� ������ ������� �� SQL (������������ �� SQL e ���� ����� ������� �� ������������ ������������� �������), ����� ������� ������� �� ��������� ����� �� ������ � �������� area, subject, sender, problemsolution. �� �������� � ������������ ��� �������� �� ���������, �� � ����������� �������� �� ������ ���������� �� �� ����������. �������� �� ������ �� �������� (getArea(), getSubject() � �.�.) ������ ������ ����������� ����. �� ������ � ORACLE ������ ����� �� �������� JDBC � ������������ ���� �� ������ �� ORACLE - oracle.jdbc.driver.OracleDriver ����� ���� �� �� ������� �� http://technet.oracle.com. �������� ��������� �� ������ �� ORACLE �� ������ �� ���� �� ���� ����, � � ��� ����� �� ������ � ��� classes111.zip, ����� ���� ���� �� �� ������� �� ��������� ���� � ������ �� ���� ������� � �������� �� JSP engine-�. ���� ���� � �� ����� ���� SearchBean, ������ ��� �� ���� � CLASSPATH-�, JAVA ����������� ������ ���� �� �� ������ � �� �� ������ ��������� �� ������. �����������, ����� �� ������� �� ����������� � ������ �� �������� � ������ �� �� �������� �� ����� ������. ������ ���������� �� ��� ���� �� �� ������ � ��������������. ��� � ���� �������� �������� �� ������������ �� JSP ������� Search.jsp, ����� �������� ����� SearchBean �� ��������� �� ����� ����� 9814566 �� ��������� emails �� ORACLE-������:

��� ����� � ����������� � ASP (Active Server Pages �� Microsoft), ���� �� ������� �� �������� ������������ ������� ����� JSP � ASP. � ����� ���������� ��������� � ���� � �����, �� ����� �� ���� ���� � ��� ASP �� ������ VBScript ��� JScript, � ��� JSP � JAVA. ��������� ���� � �� ����� ���������� �� ����, ���� ������ ���� �� �������� ��������. ����� ��������� �� JSP � ASP ��� ��: http://java.sun.com/products/jsp/jsp-asp.html .

��������� �� ����� JAVA � ������������, ����� JAVA �������� ���������� ����������� �� ������ � ������ ����������, ����� �� �������� � ���� WEB (����������� JSP), ���� ��������� ����������, ����������, ������������ � �����������. ������������ �� JSP � bean-���, Enterprise Java Beans, RMI � ������������ �� XML ������ ������������ ���������� � �� ���� �������� ������������� ���� ��� �� �������� ����� �������� ������������ ������. ��� ���� JSP � ���� ����� ���������� ����������, ����� ����� ��� ��������� ���� �� � �������� � ���� ��������� �������� �� ������ �� ����������� ����������, ������ ��� ��� ��� ����� ��� �� �� �������, �� �� �� ������� ������� �� INTERNET ����������� ��� ��-�����.

������ �������� ��������� � bean-��� � ���������� ������ �� �������� � ������� ��������. ����������� Debian/GNU Linux � JDK 1.2, Apache 1.3.9, Tomcat 3.1, Oracle 8i on Windows NT 4.0 � Internet Explorer 5.0.

 

������ ���������� �� JSP ������ �� �������� �� �������� ������:

http://www.servlets.com/resources/urls/document.html

http://java.sun.com/products/jsp

http://www.esperanto.org.nz/jsp