I have never heard of "2PL" before, but anyway:
Pessimistic means you actually lock the data when you select it to make sure nobody else can update it before you do. For example in Oracle you would SELECT ... FROM ... WHERE ... FOR UPDATE;
Optimistic means that you do not lock the data when you select it, but when you subsequently update it you check that it has not been updated by someone else in the meanwhile, otherwise your update fails. There are various ways to do this - record version numbers, last_update timestamps, or just check all the data values like this:
UPDATE ...
SET val1 = :new_val1, val2 = :new_val2, ...
WHERE key = :key
and val1 = :old_val1, val2 = :old_val2, ...;
(:old_val1, :new_val1 are variables holding the selected and modified values for column val1).
Pessimistic locking requires that a database session is maintained between the select and the update. In web-based applications, no database connection is maintained and so optimistic locking must be used.