?
Solved

conversion

Posted on 2005-03-29
18
Medium Priority
?
248 Views
Last Modified: 2010-04-01
i have one Ejb class.It will return a map object.That map will contains another map object and that map object contain value object.I have to get the values of the value object(String value ,it is the string format of Byte array).I need to access those values in the jsp and convert it into Byte array and to convert it to Image.Can u please suggest me a way to implement this thing in jsp
0
Comment
Question by:surajguptha
[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
  • 9
  • 5
  • 3
  • +1
18 Comments
 
LVL 21

Author Comment

by:surajguptha
ID: 13651533
can anybody suggeset me way to solve this problem
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13651549
I would do this in a servlet and then use RequestDispatcher to forward it onto the JSP. That way, you aren't mixing your logic code in your presentation layer. That way you can use the normal method to convert your byte array into the picture.
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13651566
Using somehting along the lines of:

ByteArrayInputStream bis = new ByteArrayInputStream (bytear,0,bytear.length);
JPEGImageDecoder dec = JPEGCodec.createJPEGDecoder(bis);
BufferedImage bim = dec.decodeAsBuffredImage();
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Author Comment

by:surajguptha
ID: 13651575
One servlet I have,that will load when the application called and that servlet only returning the map Object
0
 
LVL 21

Author Comment

by:surajguptha
ID: 13651741
i hav one object that containds another map object.How can i iterate that map.can tell me one way
0
 
LVL 21

Author Comment

by:surajguptha
ID: 13651751
I have one map object that containds another map object.
the second map object conatins a value object and that value object contains some sort of string value
How can i iterate that map and get the string value through jsp.can tell me one way
0
 
LVL 21

Author Comment

by:surajguptha
ID: 13651847
can anybody suggeset a problem to solve this

 Map mparentMapObj=CacheObjectPool.getMCache();
this is the First Map Object
from this object i need  get another Map object .How can i do that..Plz help me out to solve this problem
0
 
LVL 21

Author Comment

by:surajguptha
ID: 13651993
can u tell me how can i convert a string value to byte array
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13652047
if it's a map then you can either call it by name using the get( String name) method

    Map map = (Map)mparentMapObj.get("name_of_map");

or iterate through the values of the map

   // Iterate over the values in the map
    it = mparentMapObj.values().iterator();
    while (it.hasNext()) {
        // Get value
        Object value = it.next();
    }
0
 
LVL 21

Author Comment

by:surajguptha
ID: 13652135
can u tell how can i convert one String value to Byte array.please
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13652257
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13652269
or ratherpublic byte[] getBytes(String charsetName) as you need the bytes

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#getChars(int,%20int,%20char[],%20int)
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 13652552
you should not be doing it in jsp... whenever you are dealing with images, its best to use servlets ( atleast you are saved from being your byte stream getting ruined because of one white space left in the jsp).
I wd take the map in the servlet, read the bytes ( not chars).... set the response header to img/jpeg and then dump the stream on the output.

then this servlet can be used under <IMG> tags of HTML ( which can be inside a jsp)..

0
 
LVL 21

Author Comment

by:surajguptha
ID: 13659144
Can u tell me the way to display one image  using BufferedImage in jsp
0
 
LVL 3

Expert Comment

by:arun99907
ID: 13661345
You need to write a separate Servlet for that.

Say Servlet name is : imageDisplay.java

mapped in web.xml as /servlet/imageDisplay

Assume you are having folder structure like this:

WebApp
  -> Jsp
    ->display.jsp
  -> WEB-INF
         -> classes
                ->imageDisplay.class

inside display.jsp....

<Img src="/servlet/imageDisplay">

Contents of imageDisplay servlet

class imageDisplay extends HttpServlet bla bla bla....
{

            byte[] input = EncoderUtil.encode(image,"png");

// refer to www.jfree.org it uses org.jfree.chart.encoders.SunJPEGEncoderAdapter and further to get byte array. Its an open source.
             
               if(input !=null && input.length>0)
                {
                     BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
                     bos.write(input, 0, input.length);
                     bos.flush();
                     bos.close();
                }
}
0
 
LVL 3

Accepted Solution

by:
arun99907 earned 2000 total points
ID: 13661417
http://www.codecomments.com/archive250-2004-6-202822.html
http://swc.projects.semwebcentral.org/site/xref/org/semwebcentral/gforge/theme/tabs/GraphicUtil.html

This link will solve ur problem

http://www.mail-archive.com/struts-user@jakarta.apache.org/msg79215.html

BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight,
BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();

graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHi
nts.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
// save thumbnail image to OUTFILE
BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream(thumbFile));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
int quality = Integer.parseInt(inQuality);
quality = Math.max(0, Math.min(quality, 100));
param.setQuality((float)quality / 100.0f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
0
 
LVL 21

Author Comment

by:surajguptha
ID: 13668959
Can u please tell me which package the MemoryStream class includes.Am using that class in the jsp.
0
 
LVL 3

Expert Comment

by:arun99907
ID: 13669624
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
If you're a modern-day technology professional, you may be wondering if certifications are really necessary. They are. Here's why.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

762 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