| Author |
How can an applet receive byte array object as param??
|
nausheen fatma
Greenhorn
Joined: Sep 27, 2012
Posts: 5
|
|
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??
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
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
Joined: Sep 27, 2012
Posts: 5
|
|
|
I did not get you sir,could you explain a bit more...
|
 |
nausheen fatma
Greenhorn
Joined: Sep 27, 2012
Posts: 5
|
|
|
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
|
 |
Richard Tookey
Ranch Hand
Joined: Aug 27, 2012
Posts: 362
|
|
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
Joined: Sep 27, 2012
Posts: 5
|
|
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
Ranch Hand
Joined: Aug 27, 2012
Posts: 362
|
|
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
Joined: Sep 27, 2012
Posts: 5
|
|
|
Thanks alot,its working now,after doing Bas64 encoding.
|
 |
 |
|
|
subject: How can an applet receive byte array object as param??
|
|
|