• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

conversion

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
surajguptha
Asked:
surajguptha
  • 9
  • 5
  • 3
  • +1
1 Solution
 
surajgupthaAuthor Commented:
can anybody suggeset me way to solve this problem
0
 
bloodredsunCommented:
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
 
bloodredsunCommented:
Using somehting along the lines of:

ByteArrayInputStream bis = new ByteArrayInputStream (bytear,0,bytear.length);
JPEGImageDecoder dec = JPEGCodec.createJPEGDecoder(bis);
BufferedImage bim = dec.decodeAsBuffredImage();
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
surajgupthaAuthor Commented:
One servlet I have,that will load when the application called and that servlet only returning the map Object
0
 
surajgupthaAuthor Commented:
i hav one object that containds another map object.How can i iterate that map.can tell me one way
0
 
surajgupthaAuthor Commented:
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
 
surajgupthaAuthor Commented:
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
 
surajgupthaAuthor Commented:
can u tell me how can i convert a string value to byte array
0
 
bloodredsunCommented:
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
 
surajgupthaAuthor Commented:
can u tell how can i convert one String value to Byte array.please
0
 
bloodredsunCommented:
0
 
bloodredsunCommented:
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
 
KuldeepchaturvediCommented:
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
 
surajgupthaAuthor Commented:
Can u tell me the way to display one image  using BufferedImage in jsp
0
 
arun99907Commented:
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
 
arun99907Commented:
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
 
surajgupthaAuthor Commented:
Can u please tell me which package the MemoryStream class includes.Am using that class in the jsp.
0
 
arun99907Commented:
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 9
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now