�������� ������������ � Java � ���� 5

������:

������� �����, �� ���. ������� ��������

Web-site: http://www.nakov.com

����� ���������, �������������� ���������� ��

E-mail: [email protected]

�������� �������: 10.07.2002

 

� ����������� ���� �� ����� ���������� ������ �� ����������� �� Java ������. � ���� ���� �� �������� ����������� �� ���� ���� � �� ��������� � ������ �Web-�����������.

 

JAVA ������ � ���������

����������� �� �������� � ����� ����� �����. ����� ���������� �� �� �� �������� �� ��������� ������� � ������, ��� �� ����� �� ����� �������� �� ����� ��, ��� ����� �� ��������� ������ ����� ����������, �� �������� email-� �� ������ ��� ��� �� ��������� ������� ����� ����������� �������. ��� ���� �� ���� �������� ������� � ���������� �����. ����������� � Java � ���� �� ������ ��������� � �� ����������� �� ���� ��������� ���� � ��� java.policy. � ���������� �� �������, ����� Web-��������� ���� �� ���� �� ������, �� �������� ��������� ����, ����� �� ������ � ����������� ������ �� ����������� �� ����. � ����� �������� ������� ����� �� �� ���������� � �� ������� ���������� ������������ �� ���� ����� ������� �� ���������� �������, � ����� �������� �� ������������ �� ������������� ��. ��� ������������ �� � ������� ���� �����, �� ��������� ������������ ��������� �� ������� �� ��������, ����� ������� �������� �����������: �������� �� ����� �� ����� � ����� �� ����� �� ��������, �� ����� �� ����������. �� ����� �� ������������ ������ �� ����� �����, ���� � ����������� �������, � ����� ���� ������ �� �������. �� ����� �� ������� ����� �� ���������� ������ � ��������. ����� �� ������� ����� ���� �� ����-�, �� ����� �� ��������. �� ����� �� �������� �������� native ���. �� ����� �� ����������� ������������ ��� �������� �� ��������, �� ����� �� ����������. ���������� � �������� �� �� ����� � ����� ���������� ��������, �� ���� �� ����� �� ������ � �������� � ����������� �� ����������� �������� � ����������� ������, ����� �� ���������. ������ �� ������� ��������� �������� �� ��������. ��������� ��� �� ����� ������, ����� ��������� ������� ������� �������, ���� �������� ������ �� Chat, ������ �� ������ �� email, ������ �� ��������� �� email, �������� ���� � �.�. ������ �� ��������� ����� �������� ����������� � ��������, �� ������� ����� ��� ��������. �������� ��� ����������� �� ���� ������� ���������� ��� ������� �� ����������� SMTP ������. ����, �����, �� ����� ��������, ����� ��� ������������ �������� �� Java. �������� ���� ����� �� �� �������� ���� ����� ���� �� �������, �� ����� �� ��������, �.�. ��� ����-� ������ �� ������ getCodeBase().getHost(). ��� ���� ������, ����� �� �� �������� �� ����� Web-������, � ������� �� ��������� �������, ���� �������� �� ������� HTML ����, ����� ����� �� ������� ������� ������. ���� �������� ������������� �� ����� ���� HTML ��������� ��������� ������ ��� ����������� ��������. ������ ������, ����� ��������, �� ������� ������ ��� ��������, �������� ������� ������ ��� �������, �� ����� �� �������� � �� ��� ��������� ������������ ��� �������� ����, �.�. ��������� Web-������� ���� ������ (�������� ����������� ������). ������ �� ������ �� ����� �����, ����� ���������� ���� ������, � ���������� �� Web-�������, ������ �� ������ ���� ����� �� ������ ������� ������������ ������, ����� ��������� ������������� �� ������ � ��������, �� ����� ��� ������ �� ����������� ������. ������� ��, ���� ������ �� ����� ���� ������� ������������ �� ����������� � ���������. �� ����� ���-������ � ��������, ����� �� ����� �� ������������� �� ������ �� �� ��������� � Web-�������, �� �� ���� �� �������� ������������ �� ������� �� �����������, ����� � �������� ������. ��� ����� ���� �� ����� ���� �� ������� ��-������� � ����� ���� � ������ �� Web-����������.

���� ���� ����� ��� ���� ������ �� �����, � ����� �� ������������� ������ � ������������ �� AWT � ����������� �� ���������, ���������� � �������� �� ���������� �� �����������. �� �� �������� �� ������ ������������ �� ����� ����������, ����� ������ �����. ������� �� ��� ������ �� ����� ���������, ��� ���� ���� �� ��������� � ���� ����� �� ��������. �� ������������ �� �������� ��� �������� �� ������� � ����� �����-���������� �������� ����� ��� �����. �� ������������ �� �������� ��� ������� �� ������� ��� �������� ����� ������ ������ �� �� �� �������, � ��� ��������� ������ �� ������� �� �� ������������ �������. ��� ���� �������� ���������� �� ������:

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

 

public class SumatorApplet extends Applet {

��� TextField number1Field = new TextField();

��� TextField number2Field = new TextField();

��� Button calcButton = new Button();

��� TextField sumField = new TextField();

��� Color lastBackground;

 

��� public void init() {

������� this.setBackground(Color.black);

������� // Set layout manager to null

������� this.setLayout(null);

������� // Create the first text field

������� number1Field.setBounds(

����������� new Rectangle(20, 50, 60, 25));

������� number1Field.setBackground(Color.white);

������� this.add(number1Field, null);

������� // Create the second text field

������� number2Field.setBounds(

����������� new Rectangle(95, 50, 60, 25));

������� number2Field.setBackground(Color.white);

������� this.add(number2Field, null);

������� // Create the "calculate sum" button

������� calcButton.setBounds(

����������� new Rectangle(170, 50, 90, 25));

������� calcButton.addActionListener(

����������� new ActionListener() {

��������������� public void actionPerformed(

������������������� ActionEvent e) {

������� ��������������� calcSum();

��������������� }

����������� });

������� calcButton.setLabel("calc sum");

������� this.add(calcButton, null);

������� // Create the result text field

������� sumField.setEditable(false);

������� sumField.setBackground(Color.gray);

������� sumField.setForeground(Color.white);

������� sumField.setBounds(

����������� new Rectangle(20, 85, 240, 25));

������� this.add(sumField, null);

��� }

 

��� public boolean mouseDown(Event evt,

��� int x, int y) {

������� lastBackground = this.getBackground();

������� this.setBackground(Color.red);

������� return true;

��� }

 

��� public boolean mouseUp(Event evt,

��� int x, int y) {

������� this.setBackground(lastBackground);

������� return true;

��� }

 

��� private void calcSum() {

������� try {

����������� long s1 = new Long(number1Field.

��������������� getText()).longValue();

����������� long s2 = new Long(number2Field.

��������������� getText()).longValue();

����������� sumField.setText(s1 + " + " +

��������������� s2 + " = " + (s1+s2));

������� } catch (Exception ex) {

����������� sumField.setText("Error!");

������� }

��� }

 

��� public void paint(Graphics g) {

������� super.paint(g);

������� Font font = new Font(

����������� "Dialog", Font.BOLD, 23);

������� g.setFont(font);

������� g.setColor(Color.blue);

������� g.drawString(

����������� "Nakov sumator applet", 20, 32);

������� g.setColor(Color.white);

������� g.drawString(

����������� "Nakov sumator applet", 18, 30);

��� }

 

��� public static void main(String[] args) {

������� Frame frame = new Frame("Sumator");

������� frame.setSize(280,160);

������� SumatorApplet applet =

����������� new SumatorApplet();

������� applet.init();

������� frame.add(applet);

������� frame.setVisible(true);

������� applet.start();

��� }

}

� ������������������ ���� �� ������ ����� �� ������ �������� null �� Layout Manager. Layout Manager-�� ����� �� ���������� �� AWT ������������ � ���� AWT ��������� � ���� �� � ����� ������� ��� ��������� �� �����, ����� ����� �� �������� ��������� ��. � ������ ������ �� ������� � ��������� ���������� � ������� �� ������������, � �� � ������� � ����������, ���������� �� Layout Manager-� � ������ �������� �� LayoutManager �������� null, ������ �� ������������ ���� �������� � �����. ���� ���� ��������� ������������ ���� �� ���� � ������� �������� ����, ������� �������� ����, �������. �� �� ��������� ��������� ���������� �� ������ �� ��������, ���������� ������� addActionListener, ����� ������ ���� ��������� ����� �� ����, ����� ������������ ���������� ActionListener. �� ���������� �� ����� ���������� ���������� ��������� �� ����� �� �������� ����, ����� ��������� ActionListener ���������� � � ������ �� ��������� �� ����� actionPerformed() ������� ������ �� ����������� �� ������ calcSum(). �� ���������� �� ��������� �� ������� ��� ��� ������. �������, ����� ��� ��� ���������� � �� �� ���������� �������� MouseDown(), MouseUp() � �.�. �� ������� ����, � ������� � �� �� ������ MouseListener � ������ addMouseListener() �� ����� ������� �� ���� � ���������� �� ActionListener. ����������� �� ���������� �� ��������� ����� ����������� �� ����� �������� ������, �������� �� � ����� � ������� ��������� �� ���������� � ������ �� ���������. ��� �� ����� ��� ������������ ������ �� �������� � ����� ��� ��� �� ����� ���������� ��� ������� ����� ������, ���������� � �Error!�. �� ������������ �� �������� � �������� � ������ paint() �� ��������� ����� ��� �����. ����� � ������� paint() �� ������� paint() ������ �� ������� �� ���� (super.paint()), �� �� ����� ������������, �������� � ������ �� �� ����������� ����� ���, ������ ������� �� ����������. � ������ ���������� �� paint() ������ ���� ����������� �� ������� paint() �����, ��������� ���������� ��� �������� �� ������ � ����� �� ������ � ������������� ��. ���� ���� ������ �� ����� � �� ��������� ����� �����, �������� � 2 ������� ������ � ������. ���� �� ������� ������������� �� �����. ������ ����� ��� ��� ���� ��������� ���������� � ���� �� ������ � ���� ������������� ��������. �� ����� ��� ��� main() �����, � ����� �� �������� ������ � ���� ����� java.awt.Frame, ���� ����� ��� Frame-� �� ������� ������, ������� �� �� ��������� � �� ������� �� ������. ���� ������� ���� �� ���� ��������� �� ������� ���� ���� ������������� ��������, � ������ � �����, ���� �� �� ������ � � ��������, ������, ����� ������ �������� �� ������ �� �������� ����� � ���������� �����, � ����� �� ���������. ��� �������� HTML ���, � ����� �� �������� ������:

<html><body><center>

<applet code="SumatorApplet.class"

��� codebase="." width="280" height="130">

</applet>

</center></body></html>

����������� ���������� codebase=�.�. � ���� ���� �� �� ������ ���� �� ������������, � ����� �� ������ .class ����� �� ������. ����� <applet> ��� � ����� ���������, �������� ARCHIVE="SomeArchive.jar", � ����� ���� �� �� ������ ���� � ����� �� JAR �����, ����� ������� ��������� �� ������. ��� ��� �������� ������ ����� ��� Netscape Navigator:

� �������� � ����� ��� �������, ����� ������� ��������� ������. ������� ������ �� ����� ���� � Web �������� �� ICQ, �������� �� ����� http://icqlite.icq.com. ������� �� ��������� �� ��-������ ������ �� JDK �� 1.1 �� ������� �� �������, �� �������� �� ����� �������� � ���������� ����������. ���� � ����� � ������� ������ � �� ������ ������ ������ �� Microsoft �� �������� Java. �� ������� ������ ����� Internet Explorer � ���-������ ������������ ������� � ��� �������� ���� JDK 1.1. �� �������, �����, ���� ������ �������� ���������� ����� �� ������� �������� � ������ �� �� ������� ������������ ������� �� ����� �������� ��� ������������ �� Web-������� �������. ������������ ������ �������� ���������� � ���� ������ � Macromedia Flash, ����� � ������������� ������ �� ����������. ��, �����, ���� ������ ���, ����� ��� Java � ������ ���� �� ���� �� ������� ��������.

������ ���������� �� AWT, ���������� �� ������, ������� � ����� ��������� ������ �� �������� �� ����� �� �����: http://inetjava.sourceforge.net.

 

�� ���� ������ ���� �� ��������� ������������ � Java� ��� �� ��� ������������ �� ��� ������� ����������: ����� ������������, ������ � Web-����������. �� ������� ����������� ������� ��� �� ��� � �������������� ������������ � TCP, UDP � Multicast ������ � ������������ �� Java ������. �������� �� ���������� � ���-����� ���� �� ����� � ������������ �� Web-����������.

 

Web-���������� � JAVA

Web-������������ ������������� ������������ �������, ����� �� �������� ���� �������� ��� ������� ����� ���� ���������� Web-�������. �������� ������ Web-�������� ������� �� ���������� ���� (���� mail.yahoo.com, abv.bg, mail.bg � ��.) ������������� Web-����������. �� ������ �� ���� Web-�������� �������, � ���������� ������������ �� ��������� ��� ���������� Web-������� (�������� Internet Explorer) � ������ � ���������, �� ����� �� ������ ���� �������. ���������� �������� �� ����������� ���� ��������, � �� ������ �� ��������� �� �������� ������� �� ������ Web-���� � ������� �� ���������� ������������� ������� WWW. ���������� ������������ ������������� ������� WWW (World Wide Web) ������������ ������������ �� ������ ������� � ��������, ������������ ������ �� ������� ���� ���������� Web-�������. ������� � �������������� �� ����������, �� ����� �� � ���������. ������� �� � ������������� �� �������������� ����� ���������, ����� � ���������. �� ������������� �� ���������� � Web �������������� (WWW) �� ��������� Web-�������. Web-�������� ������������ �������, ����� ���������� ������ �� ������� ���������� ���� ��������� HTTP. Web-��������� ����� �� ����������� ����� �������� �������, ���� � �������, ����� �� �������� � ������� �� �������� �� ������ �� ��� (��������� ���������� ����������). �� ���� Web-������ ���� �� ��� ���� ��� ������� Web-�����, ����� �� ����� � ���������� ����� �������� � ��������� ����������. ���� ����, ������� ��, ���� �� � ���������� �� ������� Web-�������. ���� Web-���������� ������������ ��������� ������� � Web-������� ������������� ���������, �������� �� ������� Web-������ � �������� ��� � ������� �����. �� ���� Web-������ ���� �� ��� ������� ���������� Web-����������, ����� � �������� ����������, ����� �� � ��������� � ����� �� ���. Web-������������ ����� �� �������������� �� ����� �� �� ���-������������ ������. �������� � ��������� �� ������� ���������� Web-����������, �������� �� �������� � ���������� ���� �� ���� ������� �� �� ��������� ��������� � ���� Web-��������. ������� ������ �� ������ �������������� �� ��������� �� ��������� � ��������. �������� ������������ �� ���������� ���� �������� �� mail.yahoo.com ������� � ���� HTML �������� ��������� �� �������� �� ��� �������� Web-����������. ������ � ������������ �� ������ �� ����, ����� ���� ������������� ��������� �� ������ � ��������� �� �����, � ������� � ������������, ����� �� ����� �� ��������� � �� ��������� �� ������ ���� ������. ���� ������ �� ��������� ���������� �� ������� Web-���������� �� �������� �� ����������, ����� �� �������� � �������� ������� � ������������� ���������� ����������, ���������� �������� �� ������� �������.

���������� ���� Web-���� ������������ ���������� �� �������� ���������� (Web-��������, ��������, ��������� � ��.), ���������� ���������� (Web-�������� � ����� ���������) � Web-����������. ����� ����������, ���� � ����������� ���������� � ���� ���� ���� �� � ������������ �� �������� �������. ������ � �� �� �������� ������� ������� ����� ��� Web-����������, ������ � �� ����� �� ����� ������������ �� ������� ������� � �� ������� ���� ���� ���� �������.

���-����� ��� Web-���������� �� ������� �������� ��������� ������� �� ������������ �� ������� ������ �� ����������� ���� Web. �� ������ ����� �� �������������� Web-������������ ������������� ���������� ������-������ �������. ��������, ����� ���� �����, � ������������ Web-�������, � �������� � Web-��������, �� ����� ������ Web-������������. ���������� ����� �� Web-������������ �, �� ��� ��� ������������ ������ ����� ����������� ������������. ����� ���������� �� �������� ���������� �� ������� �����������, ���� ����� � ���������. ����� ���������� ����� �� Web-������������ �, �� ������� � ����������� �����������, �� �������� ������-������� (request-response). ��������� �� ������� ���� ������ �� ������� ������ � �������� �������� �� ���� ������ � ����������� �� ��������� ������ ��� ��� ��������� �� ������. ���� ����� �� ����������� ������ ������� �� ������������ �� ������� ���������� ����� �� ������� �� ���� �������. ���� ����������� �������� ���������� ���������, ����� ������������ ������ �� ���������� � ������ �����.

Web-���������� ����� �� �� ����������� �� �������� ����� � �� �������� Web-��������� � CGI, Perl, PHP, ASP, Java/JSP � ��. ��� ������������ �� Web-���������� � Java �� ��������� ������������ Java-�������� � Java Server Pages (JSP) � ����������� �� Web-���������� �� Sun, ����� � ���� �� J2EE (Java 2 Enterprise Edition). ���� ��������� �� ���� ���������� framework (���������� �� ��������� �������� � ���������) �� ���������� �� Web-����������, ����� �� ���������� ��-�����. ���� �������� � �������� ��������� �� Web-��������������.

 

Web-������

�� ������ ����� �� �������� �������������� Web-��������� �� ����������, ����� ������� �� ��������� ���� (���������� ���� � ������������ ���� �� HTTP � 80), � ��������� �� HTTP ��������, �������� �� ��������� ���������� (���-����� ���� �� Web ����������). �������� Web-������� ����� ���� �� ������ � ������� �� �������� ���������, ����� �� ����������� � ������������, ���������� ���� ������ Web-����������. �������� ��� ����� ���� ����� Web-������ ��������� �� ��������� � �������� ����� www.mywebserver.com � ��� �������, �� �������� �� ���������� � C:\MyWebSite, �� ������ Web-��������� ������ ������� http://www.mywebserver.com/pictures/index.html, ������ ����� Web-������ �� �� ���������� ����� C:\MyWebSite\pictures\index.html (��� ����������). ������ ���������� Web-������� ���� ������������ �� ����������� �� ��������� �� �� ���� ������� �� �������� Web-���������� � ������� �������������, �� � ��������� ��������� HTML, ������� �� �������� �� ������ �� Web-������� ��������. ���� ���������� �� ������ CGI (Common Gateway Interface). ��� CGI �� ������ �� HTTP �������� Web-�������� �������� ����� CGI-�������� � ����� �� ������� ����, ����� ���� CGI-�������� ������ �� ����������� ����� ���� �������� �� ������������ ��. CGI-���������� ���� �� ���� �������� �� ����������� ����� ���� ��� script �� ������������ (�������� �� C, C++, Pascal, Perl, PHP � ��.). ��� � ����� ����������� �� ��������� ���������� �� HTML � �������� �� ���� ������ ��������, � ���� ����� ������� �������� ��� Web-�������. ����� ������ �������� ISAPI ������������ �� Microsoft, ����� ���� ���������� �� ��������� ��������� � ������� �� ���������� ��������� ��� �� DLL ����. ������������, ����� ���� � �������� �� Web-�������������� � Java � JSP/Servlets, ���� �������� ��������� � Web-������� �� ���������� ��������� ��� (Java �������), ����� �������� ��������� HTML. ����������� �� ���������� ��������� ��� ���� ����������� �� ������ �������� ��� �������� ����������. �� ������� �� ���������� � ��-���������, ������ �� �� ������ �� ����� ��������� ��������� HTML �������� �� �� ������� ������ ����������, ��� ����� � ������������� ������� �� ������� ��� ������. ������������ ����� ������� � ��������� � ���� ���������� ��� � ��-����� ��������� ������������ � ������ CGI-��������.

 

HTTP ��������

�� � ������� �� ������� �� Web-������������ ����� �� ��� �������� ��������� �� ����� �� ����������� Web-��������� � Web-���������� � HTTP (Hyper Text Transfer Protocol). HTTP ������������ ����� ������� ��������, ����� �� �������� �� ������ �� ����������� ������� ��� �����, �������� ����������� �������. � HTTP ��������� ��� ������� ���� ������ (���������� ���� �� Web-����������) � ������ (���� �� Web-���������). ���������� HTTP ���������� ������ ���� ���������� TCP ����� ������� �� ������� ��� �������. ����������� ���� �� HTTP ��������� e 80, �� ���� �� �� �������� � ����� ���� �������� TCP ����. ������������� �� HTTP �� ������ �� ������ (request) � ��������� �� ������� ��� ������� � ������� (response) � ������� �� ������� �� ����������� �� �������.

 

HTTP ������

HTTP �������� ��� ������� ������:

<�����> <URI> HTTP/1.1

<header-������>

<������ ���>

���������� �� 3 ������� ��������: �����, URIheader-������. ������� ������ ���� �� HTTP ��������, ��������� �� �������. ���-����� ������������ ������ �� GET � POST. ���� GET �������� ������� ������� ������ �� Web �������. POST ����� �� ��������� �� ����� ��� �������. ������� �� �������� � HTTP �������� �� �������� ������ � ������ �����. ���������� ������������� URI (Unique Resource Identifier) ���������� �������� �������, ��� ����� �� ������� ��������. ���� � ������ �� URL, ����� ���� ���� ����� �� ����-� (�������) � URL-��. ���������� HTTP/1.1 � ����� �������� ������� ��� ������ �������� �� HTTP ���������, ����� �� ���� ���������� �� ��������������� �� HTTP �������. Header-�������� �� ���������� ���� ������� ������������ ��������� �� �������� � ��������� �������� ���������� ������� �������, ����� �� ������ �� ���� ������ �� Web-�������. �������� ��� �������� ���� �� ��������. �� ����� ���� ������ �� HTTP ������, ����� ����� ��������� �������� �� ����� http://www.dir.bg/:

GET / HTTP/1.1

Host: www.dir.bg

¿

������ �� HTTP ��������

���������� HTTP ������ 1.1 �������� ���� 8 �������� ������: GET, POST, HEAD, PUT, DELETE, OPTIONS, TRACE, CONNECT. ���-����� ������������ ������ �� GET � POST � �� ���� ���-������ ��������� ��� Web-��������������.

GET ������� ����������� ������� �� ��������� �� ������, ������ �� �������� URI. ������, ����� ����� Web-�������� �� ����������� �� �������� ������ ���� GET ������ � �� �� ������� �� ��������� ������� � �� �� ����� �� ��������� � �������� HTTP �������. ��� ��������� �� ��������� ������ �������� ������� ������������� ��������� ���, ����� �������� ������� � ����� ��������� �� ���� � HTTP �������. ��� ���� ������ ������ �� HTTP ������ � GET �����:

GET /InetJava-2002-program.html HTTP/1.1

Host: inetjava.sourceforge.net�

Accept: */*

Accept-Language: bg

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0(compatible;MSIE 6.0; Windows NT 5.0)

Connection: Keep-Alive

Cache-Control: no-cache

¿

����������� �� ���� ������ ��� Web-�������, ����� ����� �� ���� 80 �� �������� � �������� ����� inetjava.sourceforge.net, �� ����� ����� InetJava-2002-program.html, �������� �� URL http://intejava.sourceforge.net/InetJava-2002-program.html. ��� ��� ������� ������ ������ �� �� ������� ���������, ���� ����� ���� ��� URI-�� �� ������ ������������ ����, � ���� ���� ������ �� ���� <��� �� ���������>=<��������>, ���� �������� �� ���� ��� �� �������� ���� �� ����� ��� &. �� ����������� �� ����� ����������� ������� �� �������� ���� ���������� URL-��������, �� ����� �� ������� ��-�����.

POST ������� ����� �� ��������� �� ����� �� ������� ��� Web-�������. ���������� �������� ������� ���������� �� POST �������� ����� �� ������� CGI ������ ��� ������� ����� �� ��������� ���������� �� HTML, ����� �� ��������� � ����� ������� ���������. ���� ��������� �� ������ �� ������� ���� ������� �� �������� ������. ��� � ���� ������ ������ �� HTTP ������ � POST �����, ��������� �� Internet Explorer 6.0 ��� ���� �� ������� � Web-���������� ������� �� ���������� ���� �� www.abv.bg:

POST /webmail/login.phtml HTTP/1.1

Host: www.abv.bg

Accept: */*

Accept-Language: bg

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0(compatible;MSIE 6.0; Windows NT 5.0)

Connection: Keep-Alive

Cache-Control: no-cache

Content-Length: 59

¿

LOGIN_USER=boris

DOMAIN_NAME=abv.bg

LOGIN_PASS=tajnamajna

¿

����� �� �����, ����������� �� �������� ���� ������ ������, ���� � header-�������� �� ������ ������ ������� � ������� �� ������ ��������� � ������� ���������. �� ���������� ����� header-�������� � ����������� �� �������� ������ ���. �� ���� �� �������� �� �������� ���� ������ ���. ��� ����������� �������� ����������� �������, �� �� ������� �� ��������� �����. ���������� � ������������� �� ����������� � ����������� �� �� ����� ����������� �� Web-�������� � Web-�������. ���� Web-����������� �� � ���������� �� ����� � ������� ����� ��� ����� ����.

 

�������� �� HTTP ������

�� ����� HTTP ������, ���������� ���� � ������� ��� ��, Web-�������� ����� ������� �������. ��� ������� ������ �� ����������� ������ Web-�������� ����� ���� ������, � � �������� ������ ����� ������. ��������� �� HTTP ������ ��� ������� ������:

HTTP/1.1 <���> <�����>

<header-������>

<������ ���>

<������>

������� ��� �� ������ ������ ����� � ������� �������� �� HTTP ���������, �� ����� �� ������� ��������, ��������� ��� �� ��������� ��� ��� �� ������ � ������ �������� �������� �� ���� ���. ������� header-��������. �� �������� �������� ��������� �� �������� ������, ����� � ���������� �� Web-�������. ������ ������ ���, � ���� ���� �������, ������� �� �������� � header-�������� �����. � ���������� �� ���� �� �������, �������� ���� �� �� ����� ������� �� �������� ����� � �� �������� ����� �� ����� �� ������� ����� ����� � ����� HTTP ���������. ����������� �� header-�������� � ������� �� ������� �� �� ������� ������� �� Web-�������� � ������ ���� �� �� ����������� � �������. ���������, ����� ������ �� ����� �, �� �� ����� HTTP ������ �������� �������� � HTTP �������, ����� ������� ������� ������ ��� ������. �������� �� �������� �������� � ������� 4 ��� 5. �������� �� ������� �������� �������� � 2, � ��������, ������ ��������� ���������� � � 3. ���-����� ��������� ������ ��� HTTP ������� ��: 200 � �����; 304 � ���������� �� � �������� �� �������, �������� � header-� (�������� �� �� ���������� �� �������� �� ���������); 404 � �������� �� � �������; 500 � ������ �� �������. ��� ���� ������ �� ��������� �� HTTP ������ �� ��������� �� �������� �������� �� ������� ��������� Web-������ � ��������� �� ���� ������:

C:\> telnet localhost 80

GET / HTTP/1.1

Host: localhost

¿

 

HTTP/1.1 200 OK

Date: Sat, 10 Aug 2002 16:09:18 GMT

Server: Apache/1.3.9 (Win32)

Accept-Ranges: bytes

Content-Length: 73

Content-Type: text/html

¿

<html>

<head> <title> Test </title> </head>

��� Test HTML page.

</html>

����� �� �����, �������� � ������ ������� �� HTTP ��������� � ��� 200 (�����) � ������ ������� ������. ��� � ���� ������ �� ��������� ��������� ������:

C:\> telnet localhost 80

GET /img/nakov.gif HTTP/1.0

¿

 

HTTP/1.1 404 Not Found

Date: Sat, 10 Aug 2002 16:20:17 GMT

Server: Apache/1.3.9 (Win32)

Connection: close

Content-Type: text/html

¿

<HTML><HEAD>

<TITLE>404 Not Found</TITLE>

</HEAD><BODY>

<H1>Not Found</H1>

The requested URL /img/nakov.gif

was not found on this server.<P>

<HR><ADDRESS>Apache/1.3.9

Server at test Port 80</ADDRESS>

</BODY></HTML>

�������� ��� ����������, �� � ��������� ������ ���������� ������ �� �������� HTTP/1.0, � � ���������� � �� HTTP/1.1. ���-������������ ��������� ����� ����� ������ �� ��������� �, �� ��� HTTP/1.0 ���� ��������� �� �������� �� HTTP ������ �������� ������� ������� ������ � �������, � ��� HTTP/1.1 ���� � ���� �������� �� ����� �� �� �������� �������������� ������� HTTP ������. ���� ����� HTTP/1.1 ���������� ��-���� ������ ����� � ����������� �� �������� HTTP �������.

(������ ����������� � ��������� ����)