homepage Welcome to WebmasterWorld Guest from 54.243.13.30
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
Forum Library, Charter, Moderator: open

Flash and Shockwave Forum

    
Passing a file from a servlet.
Getting a flash plugin to accept data from a servlet
darrinps




msg:1562970
 6:03 pm on Apr 28, 2005 (gmt 0)

I'm trying to do something that you would think would have been done a thousand times by others, but I've not been able to find an example anywhere.

What is needed is for a servlet to load a Shockwave/Flash file and send it to a Shoockwave/Flash plugin to display.

I can get the plugin to display a "loading ..." message, but it keep looping through the status bar and never completes.

Can anyone please tell me the correct way to send a file back from a servlet to a Flash/Shockwave plugin?


<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page">
<jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
<f:view>
<html lang="en-US" xml:lang="en-US">
<head>
<title>Measuring Volcano Shapes</title>
</head>
<body bgcolor="#000000" style="background-color: rgb(175, 175, 238)">
<center>
<!-- begin ========== s h o c k w a v e ====================
The OBJECT tag is used by Internet Explorer and the EMBED tag
is used by NetScape Navigator. You can add/edit the volcano
functionality by editing the values for:

sw1 : names of all volcanoes
sw2 : the file names of the volcano images ================-->
<!-- OBJECT tag used by Microsoft Internet Explorer =========-->
<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0" height="400" id="hw" name="volcs" width="480">
<!-- <param name="SRC" value="../dswmedia/volc_hw.dcr"/> -->
<param name="SRC" value="http://myappdev:18080/myapp/image3ddatareader?imageid=volc_hr.dcr"/>;
<param name="BGCOLOR" value="#000000"/>
<param name="sw1" value="San Francisco Peaks AZ,Black Butte CA,Mauna Kea HI,Popacatepetl Mexico"/>
<param name="sw2" value="sfpeaks.jpg,black_butte.jpg,mauna_kea.jpg,popo.jpg"/>
<!-- EMBED tag used by NetScape Navigator ===================-->
<embed bgcolor="#000000" height="400" pluginspage="http://www.macromedia.com/shockwave/download/" src="../dswmedia/volc_hw.dcr"
sw1="San Francisco Peaks AZ,Black Butte CA,Mauna Kea HI,Popacatepetl Mexico"
sw2="sfpeaks.jpg,black_butte.jpg,mauna_kea.jpg,popo.jpg" type="application/x-director" width="480"></embed>
</object>
<!-- end ============ s h o c k w a v e ====================-->
<h:form binding="#{Display3D.form2}" id="form2">
<h:commandButton binding="#{Display3D.button1}" id="button1" onclick="self.close()" value="close tool"/>
</h:form>
</center>
</body>
</html>
</f:view>
</jsp:root>

public class Image3dDataReader extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}

public void destroy()
{
}

protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException
{

String ct=request.getParameter("contenttype");

if ((ct==null)(ct.equals("")))
{
ct="application/x-director";
}

try
{
ServletOutputStream out = response.getOutputStream();
response.setContentType(ct);

byte[] image = getImage();

if(image == null)
{
System.out.println("NULL IMAGE");
}
else
{
System.out.println("Returning 3D image" );
}

out.write(image);
}
catch (Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
}

/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
}

/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
}

/** Returns a short description of the servlet.
*/
public String getServletInfo()
{
return "Displays a 3D image from the database identified by a parameter IMAGEID";
}

private byte[] getImage()
{
byte[] result = null;

String fileLocation = "C:/Documents and Settings/Administrator/My Documents/Creator/Projects/MyApp/build/volc_hw.dcr";
File f = new File(fileLocation);

System.out.println("Trying to read from: " + fileLocation);

result = new byte[(int)f.length()];

try
{
FileInputStream in = new FileInputStream(fileLocation);

//Read file into byte array
in.read(result);
}
catch(Exception ex)
{
log("Exception caught: " + ex.getMessage());
}
return result;
}
}

 

darrinps




msg:1562971
 6:50 pm on Apr 29, 2005 (gmt 0)

Got it...there was a problem with the dcr file. the code is fine as is.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved