I have a big problem and I do not know if it can be resolved or not. I want to manage the behavior of a user in the iframe (when he moves the mouse or click on or select a text from this iframe) but the problem I have to do a treatment session to the user, so I have to handle mouse events via servlets, but it seems impossible. Now I'm trying to use Javascript but I'm not sure if I can get the servlet session and also transmit to the servlet. please get an idea about this problem. This is my JSP page I just tried here to test the selection of the text but it does not work. And what about calling the session in JavaScript if it is possible.

this piece of code will detect the text selected by the user in the iframe, I tried thousands of codes with nothing.
HTML Code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <head >
        <meta charset="utf-8" />
        <title>FUZZY SEARCH ENGINE</title>
        <link type="text/css" rel="stylesheet" href="inc/style.css" />
<body id="page2">
<div style="margin-top:90px"> <span style="color:#FFFFFF; font-size:30px; letter-spacing:10px; margin-left:555px;">The fuzzy search engine</span>
<form method="post" action="Open">
 <input Name="Button_save" type="submit"  value="" id="save" >
 <input Name="Button_imprime" type="submit" value="" id="imprime">
 <input Name="Button_back"  value="" type="submit" id="back" >
<iframe style="width: 1331px;  height:600px;" src="${url}"></iframe>
<script type="text/javascript">
function function(){
     var String selectedtext;
    var frame = document.getElementById(myframe);
    var frameWindow = frame && frame.contentWindow;
    var frameDocument = frameWindow && frameWindow.document;
    if (frameDocument) {
        if (frameDocument.getSelection) {
            // Most browsers
        else if (frameDocument.selection) {
            // Internet Explorer 8 and below
          selectedtext= frameDocument.selection.createRange().text;
        else if (frameWindow.getSelection) {
            // Safari 3

For the code I want to integrate the javascript function is as follows
HTML Code:
<%  HttpSession session = request.getSession();%>
            <%com.onto.beans.Document doc=session.getAttribute("sessiondoc"); %>
            <% doc.setNbre_caractère_sélectionné(selectedtext.length());%>
//selectetedtext variable with JavaScript code.