Welcome Guest! You need to login or register to make posts.



Go to last post Go to first unread
#1 Posted : Monday, October 22, 2007 11:58:56 PM(UTC)

Rank: Member

Groups: Member
Joined: 9/10/2007(UTC)
Posts: 8

Sice the Java version does not play nice with HttpSession, I've had to resort to finding another way to pass variables back to my servlet.

I've followed the instructions on adding a form to POST with the upload. The following is my code...


<%@page errorPage="/PageErrorFull.jsp"%>
<jsp:useBean id="Layout" beanName="com.fnf.beans.data.Layout" type="com.fnf.beans.data.Layout" scope="session" />
  try {
    String sRefCo = Layout.getProperty("Reference_Company");
    String ContextPath = request.getContextPath();
    String sHeader = "/Company/" + sRefCo + "/header.jsp";
    String sFooter = "/Company/" + sRefCo + "/footer.jsp";
    String sNbrFmt = ContextPath + "/Company/" + sRefCo + "/NumberFormat.js";
    String sUpldJs = ContextPath + "/util/iuembed.js";
    String sTargetServlet = "../.." + ContextPath + "/FileUpload";
<jsp:include page="<%= sHeader %>" flush="true" />
    String sCmpny = request.getParameter("CMPNY");
    String sBrnch = request.getParameter("BRNCH");
    String sPrdct = request.getParameter("PRDCT");
    String sSlob = request.getParameter("SLOB");
    String sPolst = request.getParameter("POLST");
    String sPolno = request.getParameter("POLNO");
    String sPolcd = request.getParameter("POLCD");
    String sPoloc = request.getParameter("POLOC");
    String sMethod = request.getParameter("method");
    session.setAttribute("CMPNY", sCmpny);
    session.setAttribute("BRNCH", sBrnch);
    session.setAttribute("PRDCT", sPrdct);
    session.setAttribute("SLOB",  sSlob);
    session.setAttribute("POLST", sPolst);
    session.setAttribute("POLNO", sPolno);
    session.setAttribute("POLCD", sPolcd);
    session.setAttribute("POLOC", sPoloc);
    session.setAttribute("command", "A");
    session.setAttribute("Method", sMethod);
  <script type="text/javascript" language="JavaScript" src="<%= sUpldJs %>"></script>
  <script type="text/javascript" language="JavaScript" src="<%= sNbrFmt %>"></script>
  <script type="text/javascript" language="JavaScript">	
    //Create JavaScript object that will embed Image Uploader to the page.
    var iu = new ImageUploaderWriter("ImageUploader1", 600, 400);
    //Change the default ButtonSendText Property
    iu.addParam("ButtonSendText", "Next");
<% if (sMethod.equals("X")) { %>
    //For ActiveX control full path to CAB file (including file name) should be specified.
    iu.activeXControlCodeBase = "ImageUploader4.cab";
    iu.activeXControlVersion = "4,5,50,0";
    iu.activeXControlEnabled = true;
<% } else if (sMethod.equals("J")) { %>
    //For Java applet only path to directory with JAR files should be specified (without file name).
    iu.activeXControlEnabled = false;
    iu.javaAppletCodeBase = "/someDir/util/";
    iu.javaAppletCached = true;
    iu.javaAppletVersion = "";    
<% } %>

    iu.addParam("LicenseKey", "blah-blah-blah....");
    iu.showNonemptyResponse = "off";
    iu.addParam("CheckFilesBySelectAllButton", "true");		
    //iu.addParam("FilesPerOnePackageCount", "1");
    iu.addParam("AutoRecoverMaxTriesCount", "3");
    iu.addParam("AutoRecoverTimeOut", "5000");
    //Configure appearance and behaviour.
    iu.addParam("PaneLayout", "TwoPanes");
    iu.addParam("ShowDebugWindow", "true");
    iu.addParam("ShowDescriptions", "true");
    iu.addParam("DescriptionsReadOnly", "true");
    iu.addParam("BackgroundColor", "#ffffff");
    //Configure Image Uploader to rotate photos automatically 
    //according to the orientation stored in EXIF metadata.
    iu.addParam("AllowAutoRotate", "true");		
    //This is NOT working!!! Request stream is empty on server side
    [highlight=#ffff11]iu.addParam("AdditionalFormName", "fnf_upload");[/highlight]
    //Configure file mask to upload JPEG images only.
    iu.addParam("FileMask", "*.jpeg;*.jpg;*.jpe;*.pdf;*.doc;*.tif;*.tiff;*.gif;*.txt");
    //Set restrictions
    iu.addParam("MaxFileSize", "10485760");					
    //Set image size restrictions.
    iu.addParam("MinImageWidth", "0");
    iu.addParam("MinImageHeight", "0");
    //Exclude the source file from upload because only 
    //resized versions of the photo will be sent.
    iu.addParam("UploadSourceFile", "false");
    //Configure settings of the optimized image. Optimized image
    //is resized to 1200x1200 with JPEG quality = 60 and EXIF metadata is preserved.
    iu.addParam("UploadThumbnail1FitMode", "Fit");
    iu.addParam("UploadThumbnail1Width", "1280");
    iu.addParam("UploadThumbnail1Height", "1280");
    iu.addParam("UploadThumbnail1JpegQuality", "60");
    iu.addParam("uploadThumbnail1FallbackMode", "SourceFile");
    iu.addParam("UploadThumbnail1CopyExif", "true");
    //Configure thumbnail settings.
    iu.addParam("UploadThumbnail2FitMode", "Fit");
    iu.addParam("UploadThumbnail2Width", "320");
    iu.addParam("UploadThumbnail2Height", "320");
    iu.addParam("UploadThumbnail2JpegQuality", "60");
    //Configure URL files are uploaded to.
    iu.addParam("Action", "<%= sTargetServlet %>");
    iu.addParam("RedirectUrl", "B99PIUPLDGAL.jsp");
    iu.addParam("MessageUploadCompleteText", "Your files have been uploaded. Click 'OK' to continue to step 2.");
    //Add event handlers.
    iu.fullPageLoadListenerName = "UpdateItemAppearance";
    iu.addEventListener("FolderChange", "UpdateItemAppearance");
    iu.addEventListener("UploadFileCountChange", "UploadFileSizeChange");		
    //This UploadFileCountChange event handler displays total size of all files selected for upload.
    function UploadFileSizeChange() {
      var imageUploader1 = getImageUploader("ImageUploader1");
      if (imageUploader1) {				
        var nbr = Math.ceil(imageUploader1.getTotalFileSize() / 1024);
        var nbrFmt = new NumberFormat(nbr);
        nbr = nbrFmt.toFormatted();
        document.getElementById("TotalSourceFileSize").value = nbr;
        document.getElementById("total_size").innerHTML = nbr + ' kb';
    function UpdateItemAppearance() {
      var imageUploader = getImageUploader("ImageUploader1");    
      var cnt = imageUploader.getPaneItemCount("FolderPane");
      //Iterate through all items on the folder pane to check if the item satisfies your upload restrictions
      for (var i = 1; i <= cnt; i++) {			        
        if (imageUploader.getPaneItemCanBeUploaded(i) == false) {     
          //If it does not, highlight it with red
          imageUploader.setPaneItemDesign("FolderPane", i, "ForegroundColor=red;" +
          "ForegroundOpacity=30;BorderLineStyleLeft=Dot;BorderLineStyleRight=Dot;" +
          "BorderLineStyleTop=Dot;BorderLineStyleBottom=Dot;BorderLineColorLeft=red;" +
    function UpdateCheckedItemAppearance() {
      var imageUploader = getImageUploader("ImageUploader1");				    
      var cnt = imageUploader.getPaneItemCount("FolderPane");
      //Iterate through all items on the folder pane and check if the item is going to be uploaded
      for (var i = 1; i <= cnt; i++) {
        if (imageUploader.getPaneItemChecked(i) == true) {        
          //If it is, highlight it with green
          imageUploader.setPaneItemDesign("FolderPane", i, "ForegroundColor=green;" +
          "ForegroundOpacity=30;BorderLineStyleLeft=Solid;BorderLineStyleRight=Solid;" +
          "BorderLineStyleTop=Solid;BorderLineStyleBottom=Solid;BorderLineColorLeft=green;" +
        } else if (imageUploader.getPaneItemChecked(i) == false && imageUploader.getPaneItemCanBeUploaded(i) == true) {
          imageUploader.setPaneItemDesign("FolderPane", i, "ForegroundColor=white;" +
          "ForegroundOpacity=00;BorderLineStyleLeft=Solid;BorderLineStyleRight=Solid;" +
          "BorderLineStyleTop=Solid;BorderLineStyleBottom=Solid;BorderLineColorLeft=white;" +

    [highlight=#ffff11]<form name="fnf_upload">[/highlight]
      <table width="98%" cellpadding="0" cellspacing="0">
        <tr><td colspan="2" class="hd1">File Upload Utility - Step 1 of 3</td></tr>
        <tr><td><hr class="hr2" width="98%"></td></tr>	
          <b>Upload Files</b>
Select the files you want to upload in the pane on the right by putting a checkmark  in the upper left corner of the thumbnail. Once you have selected the files you wish to upload, click 'Next'.
<b>Note: thumbnails in red are too big to upload.</b>
        <tr><td><hr class="hr2" width="98%"></td></tr>
          Total source file size:<span id="total_size">0 kb</span>
          [highlight=#ffff11]<input name="TotalSourceFileSize" type="hidden" value="0" />[/highlight]
          [highlight=#ffff11]<input name="seq_nbr" type="hidden" value="1" />[/highlight]			
          <script type="text/javascript">
<jsp:include page="<%= sFooter %>" flush="true" />
  } finally {}

And, on the server side, I use this SIMPLE standard method of getting the parameter from the request stream.

[highlight=#ffff11]String sSeqNbr = request.getParameter("seq_nbr");[/highlight]

But since the data is not in the request stream, i get a NullPointerException.

PLEASE help me! I don't know what I have done wrong. :(



Edited by user Monday, December 17, 2007 12:12:38 PM(UTC)  | Reason: Not specified

George Ulyanov  
#2 Posted : Wednesday, October 24, 2007 1:00:28 PM(UTC)
George Ulyanov

Rank: Advanced Member

Groups: Member
Joined: 7/26/2006(UTC)
Posts: 203


Well, actually this issue connected with the secured cookies is already solved. Read the next article about it:

"PRB: Image Uploader for Java looses HTTP-only cookies".

Best regards,

George Ulyanov

#3 Posted : Wednesday, October 24, 2007 9:23:29 PM(UTC)

Rank: Member

Groups: Member
Joined: 9/10/2007(UTC)
Posts: 8

Yeah, I saw that but the article said it was only affecting FireFox and I am using IE7.

I tried it anyway and I am able to retrieve data from the session. Maybe someone should update that article to include IE also.

Thanks for your time,


George Ulyanov  
#4 Posted : Thursday, October 25, 2007 10:18:47 AM(UTC)
George Ulyanov

Rank: Advanced Member

Groups: Member
Joined: 7/26/2006(UTC)
Posts: 203

As I remember, IE supports http-only cookies since version 6. That's strange that there aren't any words about other browsers... Thanks for point to this incompleteness.
Best regards,

George Ulyanov

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.