Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How can an applet receive byte array object as param??

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiii,

I want to send an object as applet param from my jsp page which embeds the applet.and how do i receive the object inside the applet class.
This is my code :
my servlet snippet




byte[] unsignedbytearray=new FiletoByteArray().receiveObject(filename);

req.setAttribute("fileobject",unsignedbytearray);

RequestDispatcher view=req.getRequestDispatcher("showapplet.jsp");
view.forward(req, res);





showapplet..jsp (which has embedded an applet )

<%@ page language="java" %>
<%
byte[] bytearray=(byte[])request.getAttribute("fileobject");//byte array received from some servlet view
System.out.println("array object received Size is "+bytearray.length); //this gives correct output : "array object received Size is 1787264"
%>
<html>
<head>
<title>FileNameSaved</title>
</head>
<body>
<jsp:plugin type="applet" code="demoapplication.ControlFrame.class"
width="700" height="550" codebase="context" archive="file.jar,itextpdf-5.2.1.jar,bctsp-jdk16-1.46.jar,bcprov-jdk16-1.46.jar">
<jsp:params>
<jsp:param name="file" value="<%=bytearray.toString()%>" />
</jsp:params>

<jsp:fallback>
<p>Unable to load applet</p>
</jsp:fallback>
</jsp:plugin>
</body>
</html>


my Controlframe.class snippet receiving the param


try {


String unsignedPdf=getParameter("file");

System.out.println("received at applet size: "+unsignedPdf.length()); //This Gives strange output :received at applet size:10
}



Can jsp send an object as param??
 
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, you can only send text through a parameter declared in HTML (for the rather natural reason that HTML is text and only text).
 
nausheen fatma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not get you sir,could you explain a bit more...
 
nausheen fatma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ther a way where i could use jsp getproperty to receive the byte array and then send it as param to applet??? My project demands that i should avoid creating a URL connection from applet,and receive byte array directly from servlet
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

nausheen fatma wrote:I ther a way where i could use jsp getproperty to receive the byte array and then send it as param to applet??? My project demands that i should avoid creating a URL connection from applet,and receive byte array directly from servlet



Two possibilities to get you moving :-

1) Base64 or Hex or ASCII85 encode the byte array and pass that as a parameter.

2) Use something like XStream to generate an XML serialization of the object and pass that as a parameter. Some form of encoding might still be required.

Though both these might work I would first of all find out why "my project demands that i should avoid creating a URL connection from applet,and receive byte array directly from servlet" is a requirement? This seems a little strange.
 
nausheen fatma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmn.......could you provide me some link for the above solutions ,as i am new to applets..

I have already done that way, and my project lead somehow wants to get the bytearray as parameter to applet..Donno why ..
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

nausheen fatma wrote:Hmmn.......could you provide me some link for the above solutions ,as i am new to applets..

I have already done that way, and my project lead somehow wants to get the bytearray as parameter to applet..Donno why ..



http://www.google.co.uk/#hl=en&sclient=psy-ab&q=java+base64+encode+byte+array&oq=java+Base64+encode&gs_l=hp.1.1.0l4.0.0.1.1672.0.0.0.0.0.0.0.0..0.0.les%3B..0.0...1c.-oAJ9JjLams&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.&fp=1a81222e663c924c&biw=1280&bih=785
 
nausheen fatma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot,its working now,after doing Bas64 encoding.
 
Where does a nanny get ground to air missles? Protect this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic