Results 1 to 6 of 6

Thread: [SOLVED] Zimlet read+write HttpSession

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    6

    Default [SOLVED] Zimlet read+write HttpSession

    I wrote a zimlet to upload, convert a show a video file.

    In the development machine it takes few second and it is ok, but in the production machine the process takes minutes, so some kind of feedback is necessary in order to tell the user the serve is still alive.

    After a long, looong, thinking, I came out with this solution.

    The form with the file to upload has an "onClick" traps that when the user submits the form to a jsp StoreinDB page, opens a jsp popup with a status that reload itself every 5 seconds.

    The StoreinDB write in the
    httpSession
    the info for the popup.

    If the jsp in the popup doesn't find any info in the session it displays "not available".

    But I have an error in the popup, it looks like
    Code:
    [...]
    <%@ page import="javax.servlet.http.*" %>
    [...]
    HttpSession session = request.getSession();
    that, despite my import, "HttpSession" isn't recognized.

    How can a zimlet access to a session?

    Thanks

  2. #2
    Join Date
    Nov 2009
    Posts
    105
    Rep Power
    5

    Default

    Can you upload or paste your JSP code?

  3. #3
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    6

    Default

    Quote Originally Posted by sposetti View Post
    Can you upload or paste your JSP code?
    Here they are

    MVideoAdd.jsp (is simple form)
    Code:
    [...]
    <BR>
        <form  id="addvideoform" method="post" action="DoAddVideo.jsp" ENCTYPE="multipart/form-data">
    	<table border="0" width="400" id="table1">
    [...]
            <tr>
                <td align="right">Video</td>
                <td align="left"><input type="file" name="datafile" size="45"></td>
            </tr>
    		<tr>
                <td>
    
                  <input name="Submit1" type="submit" value="Aggiungi" onClick="window.open('AddA.jsp', 'popupStatus', 'toolbar=0, location=0, status=0, menubar=0, scrollbars=1, resizable=1, width=320, height=240'); ValidaForm(this.form); return false;"/>
                </td>
    		</tr>
    	</table>
    </form>
    
    [...]
    function ValidaForm(myform)  {
    [...]
    When the button "submit" is pressed a new window is opened and a status popup is opened with AddA.jsp

    In AddA.jsp I read the session content every three seconds
    Code:
    <html>
      <head>
    [...]
      </head>
    
    <body>
    <%@ page import="java.lang.*, java.sql.*, com.mysql.jdbc.Driver" %>
    <%@ page import="java.io.*" %>
    <%@ page import="java.util.*" %>
    <%@ page import="javax.servlet.http.*" %>
    <%@ page import="java.util.Iterator" %>
    <%@ page import="org.apache.commons.fileupload.*"%>
    <%@ page import="com.zimbra.cs.account.*, com.zimbra.cs.zimlet.*" %>
    <%@ page import="java.util.Date, java.text.DateFormat, java.text.SimpleDateFormat" %>
    
    <P align=center> add 1<BR>
    <img  id="statusimg" src="img/caricamento.gif" alt="caricamento" border="0">
    </P>
    <%
    [...]
    
      out.println("  setTimeout(\"window.location.reload()\", 3000);");  
    
      HttpSession session = request.getSession();
    %>
    </body>
    </html>

  4. #4
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    6

    Default

    I solved the problem! It was only that the variable "session" was already used, so I simply havn't (re)declared it.

    Just to be safe I reinizializated it
    Code:
    session = request.getSession();
    Then I found another little issue: variables coming from the session need to be casted
    Code:
    String videoName = (String) session.getAttribute(my_uid+"-videoName");

  5. #5
    Join Date
    Nov 2009
    Posts
    105
    Rep Power
    5

    Default

    Ths casting issue isn't really an issue. You can store any serializable object in a session attribute, not just Strings. So getAttribute() just returns Object that you have to cast. That's just the way to do it.

  6. #6
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    6

    Default

    Quote Originally Posted by sposetti View Post
    Ths casting issue isn't really an issue. You can store any serializable object in a session attribute, not just Strings. So getAttribute() just returns Object that you have to cast. That's just the way to do it.
    Yes, it is not a real issue: it is just something I wasn't awared of, I lost on it a couple of hours, I hope nobody else has to throw away his time as I did.

Similar Threads

  1. bayes db..
    By osiris in forum Administrators
    Replies: 9
    Last Post: 06-15-2011, 11:14 AM
  2. Replies: 6
    Last Post: 03-05-2010, 12:13 AM
  3. Samba and POSIX undeploy problem
    By catnipper in forum Zimlets
    Replies: 0
    Last Post: 09-02-2009, 10:51 AM
  4. [SOLVED] Error running mailboxd after script backup
    By ttortosa in forum Administrators
    Replies: 5
    Last Post: 10-22-2008, 01:33 AM
  5. speed up the net
    By mcesari in forum Administrators
    Replies: 10
    Last Post: 04-25-2008, 11:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •