Q. Can one place on Shabbos a glass with a mixture of vinegar or wine and a little liquid detergent, to attract and trap little very bothersome fruit flies?

A. Mishna Berura (316:18) rules that it is forbidden to set a trap (as a mouse trap) on Shabbos, and if an animal is trapped as he sets the device, he transgresses a biblical proscription. If it is trapped afterwards it is rabbinical prohibition. However, it is permitted to set a trap before Shabbos.
In regards to flypaper, Poskim disagree whether you are allowed to hang it on Shabbos. Some rule it is prohibited (Tal Nosson p. 172, P’ri Hagan 4: 316 – p. 369, Sdei Tzoifim – Beitza 36a – p. 438). However, Piskei Teshuvos (316: 9) quoting Ateres Moishe (1: 77) permits hanging flypaper since to begin with, a fly may not immediately be caught. Besides, flies and the like are not normally trapped for any particular use (Beminom Notzud), and he is only doing it to be rid of them (Melocho Sheino Tzricho Legufo). Other Poskim permit when in great need (Sdei Tzofim ibid. See also Chashukei Chemed – Shabbos 5a, in regards to placing food on an already set glue trap).
Migdal Dovid (39 Melochos 3: Tzad n. 124) permits placing a bottle with a narrow opening and draw bees into it with an attracting substance when needed, since in essence they can still exit the bottle. You may also argue that the holding power of detergent is not necessarily the equivalent of glue, and the flies can still escape.
Horav Shlomo Miller’s Shlit’a opinion is that when in need, you can set up the mixture of an attracting substance mixed with detergent on Shabbos.

Rabbi A. Bartfeld as revised by Horav Shlomo Miller Shlit”a