?
Solved

Urgent

Posted on 2008-10-14
3
Medium Priority
?
617 Views
Last Modified: 2012-08-13
I am taking ImageSnapshot of the flex component, i am sending this object to jsp page, I have to save this  object using request.setContectType(JPEG) on client  (Browser) location also client will able open it using jsp. attached code is the sample example which I did with flex. from flex i am sending this IImageSanpShot object to jsp. please let me know how will i write a jsp to save this image in JPEG format. I need JSP code, to receive this IimageSnapshot object. Can any body provide me sample jsp  file for this?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	
	<mx:Script>
		<![CDATA[
			import mx.graphics.codec.IImageEncoder;
			import mx.controls.Image;
			import mx.graphics.ImageSnapshot;
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.graphics.codec.JPEGEncoder;
			
			[Bindable]
			private var buttonsEnabled : Boolean = true;
			[Bindable]
			private var imgData:Object;
			
			private function grabScreen() : Object
			{
				
				return ImageSnapshot.captureImage( chartsContainer, 0, JPEGEncoder as IImageEncoder  ) as Object;
			}
			
		private function exportImageToJPG() : void
			{
				
				buttonsEnabled = false;
				imgData = grabScreen();
				Alert.show("Sending imgData :->"+imgData.toString());
				httpService.send({"imgData":imgData});
			}
			
			
			private function onResult( message : String ) : void
			{
				
				Alert.show(message);
				buttonsEnabled = true;
			}
			
			private function onFault( event : FaultEvent ) : void
			{
				Alert.show("Server Fault: " + event.message);
				buttonsEnabled = true;
			}
			
		]]> 
	</mx:Script>
	
	<mx:Model id="data" source="sampleData.xml"/>
	
	
		
	<mx:HTTPService id="httpService" 
    	url="http://localhost:8080/export/SampleExport.jsp"
		result="onResult('Charts saved as JPG.')" method="POST" 
		resultFormat="object"
		fault="onFault(event)">
	
	</mx:HTTPService>
	<mx:Panel 
		title="Flex Charts Example for Screen Export"
		width="688" height="456" 
		layout="absolute"  
		horizontalCenter="0" 
		verticalCenter="0">
	
		<mx:Canvas width="100%" height="250" id="chartsContainer">
			
			<mx:HLOCChart 
				x="10" y="10" 
				id="hlocchart1" 
				dataProvider="{ data.item }" 
				width="320" height="240">
				
				<mx:series>
					<mx:HLOCSeries 
						openField="open" 
						closeField="close" 
						highField="high" 
						lowField="low"/>
				</mx:series>
			</mx:HLOCChart>
			
			<mx:PieChart 
				x="338" y="10" 
				id="piechart1" 
				dataProvider="{ data.item }" 
				width="320" height="240" >
				
				<mx:series>
					<mx:PieSeries 
						field="open" 
						labelPosition="inside" />
				</mx:series>
			</mx:PieChart>
			
		</mx:Canvas>
		
		<mx:DataGrid
			x="10" y="258" 
			width="648" height="118" 
			dataProvider="{ data.item }" />
	
		<mx:Button label="Export to Image" click="exportImageToJPG()" enabled="{ buttonsEnabled }"  x="10" y="384"/>
		
	</mx:Panel>
</mx:Application>

Open in new window

0
Comment
Question by:ASHISHRAIK11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Accepted Solution

by:
Siva Prasanna Kumar earned 2000 total points
ID: 22711506
Your JSP sample code should look like this

<%@page import="java.io.*"%>
<%
String filename = "xyz.jpg";
String path = new String();

try {
ServletContext sc = this.getServletContext();
path = sc.getRealPath("/");
FileOutputStream fos = new FileOutputStream(path +"\\" + filename);
ServletInputStream instream = request.getInputStream();
int i=0;

while(i!=-1)
{
i=instream.read();
fos.write(i);
}
System.out.println("Created " + filename + " in " + path);
} catch (Exception e) {
out.println(e.printStackTrace());
}

%>

let me know if their are any issues.
0
 
LVL 19

Expert Comment

by:Gary Benade
ID: 22902306
please provide feedback or accept the answer above
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question