I have written an application where the SWF is stored on my Local Drive for Example C:/uploads/demo/demo.swf , and I have embedded the SWF file in my JSP.
But when I run my application the SWF isnt opening in any browser , but what is surprising is the SWF file opens when I run in the default browser of Eclipse.
For security reasons I know the app can not access files outside its deployed folders, but what is the work around for that.
Here is my code
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%final String UPLOAD_DIRECTORY = "C:/uploads/";
String uname=(String)session.getAttribute("user");
// out.print(uname);
String uname1="";
boolean flag = false;
String path =UPLOAD_DIRECTORY+uname ;
// out.print(" "+path);
File f = new File(path);
if(f.exists())
{
File[] listOfFiles = f.listFiles();
for (File file : listOfFiles) {
String filename =file.getName();
String ext = filename.substring(filename.indexOf("."));
if (ext.contains(".swf")) {
flag=true;
System.out.println(file.getName());
uname1=file.getPath().replace("\\", "/");
uname1 = "file:///"+uname1;
System.out.println(uname1);
}
}
}
else
{
out.println("Please Sign In after few days.................");
}
if(flag==true)
{
%>
<%}
else
{
out.println("No file to show");
}
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("<%=uname1%>", "myContent", "800", "800", "9.0.0");
</script>
<title>Insert title here</title>
</head>
<body>
<h1><a href="LogoutServlet">Logout</a>
</h1>
<div id="myContent">
<p>Alternative content</p>
</div>
</body>
</html>
I would be really greatful if someone can help.
Put in it in the webroot and refer to it by http://...
not file:///...
. Or create a servlet to read the bytes of the file from the location outside webroot where you have it, and write those bytes to the servlet response with the proper mimetype. Then reference the servlet address in your embed code.