Applety, Servlety a JSP

| Úvod | Inštalácia Mavenu | Ukážkový projekt | Applet: pom.xml | Servlet: pom.xml | Servlet: web.xml | Servlet: index.jsp | Linky | Úlohy |

Teraz si stiahnite dve ukážkové projekty tu: workspace.zip. Rozbaľte a pridajte do workspacu, rightclick v eclipse v ľavej lište s projektami - import a as existing maven project. Potom bude nutné prinútiť maven aby posťahoval závislosti, right click na project a run as a maven package. V prípade problémov skúsiť opakovne, mavenu chvílu trvá kym zaregistruje akciu, prípadne občas treba viackrát. Dostanete missing artifact v konzole (medzi informáciami o downloade a stahovaní maven vecí - maven za vás posťahuje všetky knižnice uvedené v dependencies) Potrebujete teda ešte ručne dokopírovať do .m2 adresáru,ktorý si dajte vyhľadať(mal by byť vo vašom home adresári) knižnicu netscape.. Ako? Obsah tohoto archivu netscape.zip prekopirujte do /.m2/repository, s tým že pôvodný folder overwritne - ten si vytvoril maven keď sa neúspešne pokúšal stiahnuť knižnicu zo svojich vlastných repositories. Opäť potrebujete pár krát cez run as maven package zbuildovať projekty. Na projekt servletu potrebujete špeciálnu konfiguráciu pre kontajner jetty, preto si ju teraz vytvoríme, a WebProjekt budeme púšťať teraz už len cez neho. Po skončení práce vypneme v task manageri windowsu proces javaw, resp. killneme v linuxe. Konfiguráciu urobte cez klik na run v hornej lište, run configurations, maven build, right click naň a new, a podľa obrázku you need new run configuration for jetty. Applet si zatiaľ môžeme púšťať cez run as applet, server púšťame cez run as "naša nová konfigurácia".

Teraz sa bližšie pozrieme na obsah projektov:
  1. applet slúži na upload súborov, hlavná trieda je FileUploadApplet, je ukážkovo zabudovaný na samostatnú stránku v src/web/..
  2. servlet uploadované súbory ukladá do príslušného úložiska. Je to len jedna class.

Čo treba ešte treba urobiť aby nám to celé bežalo, tj. applet fungoval v browseri a servlet komunikoval a sejvoval uploadované dáta:
  1. Na to, aby applet bežal zabudovaný aj na stránke, je potrebné ho podpísať. Najprv si vyrobíme kľúč, potom podpíšeme zbuildovaný applet.
  2. servlet uploadované súbory ukladá do príslušného úložiska.


Ako podpisovať applety? (zdroj: tu)

POZN: v prípde, že v commandline bude jarsigner a keytool neznáme, treba modifikovať enviromental variables OS, konkrétne dodať do premennej Path (prilepiť na koniec, nie prepísať!) cez ';' aj cestu k jdk vo vašom pc.

3: Generate Keys

A JAR file is signed with the private key of the creator of the JAR file and the signature is verified by the recipient of the JAR file with the public key in the pair. The certificate is a statement from the owner of the private key that the public key in the pair has a particular value so the person using the public key can be assured the public key is authentic. Public and private keys must already exist in the keystore database before jarsigner can be used to sign or verify the signature on a JAR file.

Susan creates a keystore database named compstore that has an entry for a newly generated public and private key pair with the public key in a certificate using the keytool command.

In her working directory, Susan creates a keystore database and generates the keys:

keytool -genkey -alias signFiles -keystore compstore 
	-keypass kpi135 -dname "cn=jones" 
	-storepass ab987c

This keytool -genkey command invocation generates a key pair that is identified by the alias signFiles. Subsequent keytool command invocations use this alias and the key password (-keypass kpi135) to access the private key in the generated pair.

The generated key pair is stored in a keystore database called compstore (-keystore compstore) in the current directory, and accessed with the compstore password (-storepass ab987c).

The -dname "cn=jones" option specifies an X.500 Distinguished Name with a commonName (cn) value. X.500 Distinguished Names identify entities for X.509 certificates. In this example, Susan uses her last name, Jones, for the common name. She could use any common name that suits her purposes.

You can view all keytool options and parameters by typing:

keytool -help

4: Sign the JAR File

JAR Signer is a command line tool for signing and verifying the signature on JAR files. In her working directory, Susan uses jarsigner to make a signed copy of the SignedApplet.jar file.

jarsigner -keystore compstore -storepass ab987c 
        -keypass kpi135 
	-signedjar 
	SSignedApplet.jar SignedApplet.jar signFiles

The -storepass ab987c and -keystore compstore options specify the keystore database and password where the private key for signing the JAR file is stored. The -keypass kpi135 option is the password to the private key, SSignedApplet.jar is the name of the signed JAR file, and signFiles is the alias to the private key. jarsigner extracts the certificate from the keystore whose entry is signFiles and attaches it to the generated signature of the signed JAR file.