Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Zimlets

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-12-2010, 04:23 AM
Active Member
 
Posts: 34
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
Reply With Quote
  #2 (permalink)  
Old 03-12-2010, 08:12 AM
Zimbra Employee
 
Posts: 105
Default

Can you upload or paste your JSP code?
Reply With Quote
  #3 (permalink)  
Old 03-13-2010, 04:22 AM
Active Member
 
Posts: 34
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>
Reply With Quote
  #4 (permalink)  
Old 03-14-2010, 09:26 AM
Active Member
 
Posts: 34
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");
Reply With Quote
  #5 (permalink)  
Old 03-15-2010, 08:17 AM
Zimbra Employee
 
Posts: 105
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.
Reply With Quote
  #6 (permalink)  
Old 03-15-2010, 10:03 AM
Active Member
 
Posts: 34
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.