Problem in drawing image on the fly using jsp

I have been searching the forum and web for the problem but in vain. I have wrote a jsp which creates an image on the fly from the data selected from the database. But after the image is drawn, it throws an IllegalStateException. The offending code is at the time of releasePageContext() method of the compiled jsp. I am using the following code in jsp to display the image.
BufferedImage bi = obj.getBufferedImage();
javax.imageio.ImageIO.write(bi,"png",response.getOutputStream());
I even tried to do the same with servlet, but the problem is that when I am using forward action in jsp I am getting the image but the control is in the servlet and if I am including the servlet, I am getting junk characters instead of image. I have set the content type in servlet and also in jsp.
Thank you in advance.

Hi all,
I've developed a web application using glassfish server... my database is postgresql.... i try to generate a report using Jasper Reports.... i've succesfully developed the report template..... My problem when ever i try to generate a report it gets the data from the back end.... and throws the following error.....
StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:652)
at org.apache.coyote.tomcat5.CoyoteResponseFacade.getWriter(CoyoteResponseFacade.java:196)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:149)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:142)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:216)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:134)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:89)
at org.apache.jsp.GenerateBirthCertificate_jsp._jspService(GenerateBirthCertificate_jsp.java:149)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:353)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
i've written my code in jsp.... My code is....
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page language="java" import="java.io.*, net.sf.jasperreports.engine.*, java.sql.*, java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CDAC Portal</title>
</head>
<body>
<%
try {
Connection con=null;
String query="";
String regNo="";
regNo=request.getParameter("regNo");
regNo = regNo.toUpperCase();
out.println("Registration No :"+regNo);
Class.forName("org.postgresql.Driver");
con = DriverManager.getConnection("jdbc:postgresql://192.168.31.79:5432/Municipality","postgres","");
System.out.println("connected succefully");
ServletContext context = this.getServletConfig().getServletContext();
File reportFile = new File(context.getRealPath("/reports/birth_cert.jasper"));
query="select * from birth_details where regn_unit='"+regNo+"'";
Map parameters = new HashMap();
parameters.put("regNo",""+regNo);
parameters.put("query",""+query);
byte[] bytes = null;
try {               
bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, con);
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
} catch (JRException e) {
System.out.println("Error : "+e);
con.close();
} catch(Exception exc) {
System.out.println("Connection pool error :"+exc.toString());
%>
</body>
</html>
can anyone help me hw to solve this problem....
Thanks in advance
R Vijay,
Project Engineer,
CDAC, Chennai.
India
[email protected]
[email protected]

Similar Messages

  • How to upload the image and diplay the image in the browser using jsp

    How to upload the image and diplay the image in the browser using jsp
    thanks
    shan

    i'll suggest looking for sample code or tutorial with a relevant query in google, which as far more time than us to answer this type of reccurent question

  • How to create thumbnail images on the fly from JSP or servlet?

    Hi all,
    Iam new to this forum. I need a solution for the problem iam facing in building my site. Ihave groups and briefcase section in my site. I allow users to upload files and pictures.
    When they upload pictures i need to create thumbnail for them on the fly.
    Is there any taglibs or java source to do this from JSP or servlets.
    It would be very greatful if i can get an early answer.
    Please let me know if there is any other forum where i can get better answer, if not here?
    thnx.

    Here is how you can create dynamic images:
    http://developer.java.sun.com/developer/JDCTechTips/2001/tt0821.html#tip2
    However, if you want to create gifs/jpegs and save them to the disk it depends from where you want to create the images. It is different if you are creating from another image or just drawing one from scratch etc.. But in the end you will probably need to use one of the imageencoder classes and write the result to the disk with the file io classes.

  • Problems while accessing images outside the web document-root folder

    Our application runs on Oracle application server on Linux. Facing problems while accessing images outside the web document-root folder. This works with changes in global-web-application.xml by including the <virtual-directory> tag. The same change does not work when done on Linux machine. It is unable to find the image. Please help in resolving this issue.
    </locale-encoding-mapping>
    </locale-encoding-mapping-list>
    </web-app>
    <virtual-directory virtual-path="/img" real-path="/home/eposuat/" />
    </orion-web-app>
    Code in the jsp:
    <img width=700 height=700 src="/img/3.tif"></img>
    <img width=700 height=700 src="/img/WB.gif"></img>

    This is one of the least satisfactory aspects of site management in Dreamweaver, and several developers, including myself, have been pressuring the Dreamweaver team for some years to improve this. Who knows? They might eventually take notice.
    The only way to do this at the moment is to create two site definitions, one nested inside the other. Set up the site definition normally based on htdocs as your site root. Then create a new site definition based on site. Dreamweaver will nag you that it can cause problems, but it won't actually stop you from doing it. The only potential problem is with site synchronization.
    The problem with using site as the only basis for your site definition is that Dreamweaver automatically puts things like the Connections, Scripts, and other folders in the site root. So, everything ends up at the wrong level of the site hierarchy. Quite frankly, the whole thing is a bit of a pain. Dynamic site development was added to Dreamweaver only in version 6 (Dreamweaver MX), and no one had really thought through the need to store files outside the site root.

  • How to upload a file which may contain text as well as image to the server using windows phone 8 application ?

    How to upload a file which may contain text as well as image  to the server using windows phone 8 application ?

    You're going to need to give way more detail about the situation before we can help.

  • Why can't i download e-mail attachments and images from the web using firefox browser

    i am using a Mac laptop.
    when i try to download my e-maill attachments, the Download tab appears. but when i click the download "key", nothing happens.
    i also can't save images from the web using firefox. the Save this Image tab appears but when i try to save, nothing happens.
    when i check on my Downloads folder, only unreadable files like these appear:
    1ttOnsY3.doc.part
    2Sf9jyNT.doc.part
    62+fxHoe.doc.part
    ASx1ZO9N.xls.part
    BtRlxR4R.exe.part
    dZmKC1nU.doc.part
    ehmb9rox.doc.part
    FJx+ku02.doc.part
    FSR7ckkV.doc.part
    hvlqg5Qy.exe.part
    JwVExec0.doc.part
    KEBM+klW.doc.part
    but when i try to use my Safari browser, download is successful.
    ive tried reinstalling my Firefox (version 3.6) but to no avail

    Not all 10g links are wrong however a number of them are as follows:
    Oracle ADF Installer (10.1.3.2) (Version 10.1.3.2, build 4066)
    Oracle ADF Installer (10.1.3.1) (Version 10.1.3.1, build 3984)
    Oracle JDeveloper 10g (Version 10.1.2.3, build 1936)
    Oracle JDeveloper 10g (Version 10.1.2.2, build 1929)
    Oracle JDeveloper 10g (Version 10.1.2.1, build 1913)
    Oracle JDeveloper 10g (Version 10.1.2, build 1811)
    All update this post once resolved.
    Thanks for the notification

  • Determin how many user log on the site using JSP/Servlet?

    Hi all,
    Is there a way to determine how many user log on the site using JSP/Sevlet? I'm running Apache 2.x & Tomcat 4.x
    I'm trying to get a list of user currently log in the site.
    Please help!
    Thanks,
    -JN-

    You could use the HttpSessionBindingListener interface. Every time a user logs into the session put a user object into the session. The user object will implement the HttpSessionBindingListener interface. When the user object is added to a sessiion it recieves an event and it increments a counter. When the session times out or you invalidate the session because the user has logged out the user object will recieve an event and it can then decrement the counter.
    This will at least tell how many active user sessions there are.

  • Generating images on the fly to use as backgrounds for components

    I am creating an application that has an input number slider with a background image. I would like to change the background image on the slider based on its position (as chosen by the user) using a partial trigger.
    I have successfully been able to do update the background images if I have these images inside of my "Web Content" folder within my JDeveloper project. Instead, I would like to be able to generate the images as needed. These images are color gradients where the start/stop of the gradient is based on the slider's thumb position (as well as other user-defined variables). Because there are many different images that could possibly be created, I am looking into generating the images at runtime rather than have hundreds of images stored somewhere.
    I am trying to generate these images using a BufferedImage that I can then write to a file. The path I am saving it at is as follows:
    FacesContext fc = FacesContext.getCurrentInstance();
    ServletContext sc = (ServletContext)fc.getExternalContext().getContext();
    String path = sc.getRealPath("/") + filename;
    I then create the file at the path and use ImageIO to write it:
    File f = new File(path);
    ImageIO.write(bi, "png", f);
    I am saving this file path in a variable in my backing bean that I then use on my ADF page to populate the background image field of the slider.
    Problem: when I run the page, my slider does not have a background image.
    Looking at the location where the file should be saved, it is actually "saving" it within a .war file which I don't think is appropriate (or possible, for that matter). Is there some way that I can save it either on the server side or the client side so that the client can see the background actually being updated using the generated image? I am almost positive that the path I listed above is incorrect - if this is the correct approach for this problem, where would be an appropriate location?
    Any pointers would be greatly appreciated. Thanks in advance for your help!

    Instead of saving the image to a file, why not use a Servlet to write the image to the Servlet's response stream. Then, you just point the background image to the Servlet.
    John

  • How can I draw an image in the browser using mouse

    I have to draw an image in the browser and have to store a file in the server and I don't know how can I do it. Is there anybody who konw it.

    Components other than applets cannot be downloaded into client machines
    unleess There is a Java Web Start kind of Mechanism present on client and the server also supports
    this .Hence your application is between Applet ---Xdownloadable ApplicationXX ---- traditinal Application

  • Adjust Counter Delay on the fly using two Counters

    Hi,
    I'm using the technique described here by JohnP to implement an on the fly delayed output of a hardware counter relative to it's trigger.
    http://forums.ni.com/t5/Multifunction-DAQ/Synching-AO-and-Counter-Output-arming-and-triggering-seque...
    My system generates a hardware buffered regenerative analog output.  A continuous synch pulse is generated using Cntr0 on the same PCI-6221 and is triggered off of the AO.StartTrigger in order to synchronize the Cntr0 Pulse with each generation of the AO wavefrom.  Then Cntr1 is configured in retriggerable single sample high/low time mode and triggered off of the Cntr0.InternalOuput.  By changing the low time of Cntr1 I can effectively implement an adjustable on the fly delay on the ouput of Cntr1 relative to Cntr0 and hence relative to the AO waveform.
    The technique works great for rational values of drive period, (i.e.  1.258 s), but when an irrational waveform period is commanded such as (0.59405940594059405940594059405941 s) the Cntr1 delayed pulse drifts relative to Cntr0.  Meaning if you start with a 0 second delay between the two counters, the output pulses are initially aligned but then Cntr1's output will rapidly drift such that the two counter outputs are no longer synchronized.
    Clearly there is a rounding error occuring but I can't seem to correct it.  I changed the Cntr1 high/low mode from time in seconds to clock ticks thinking I'd have better resolution but still see the same drift with irrational drive periods.  I also suspect that by calling the Cntr1 property Cntr.RdyForNewVal in a loop the hardware determinism of my system is compromised.
    Our current solution is to simply coherce the user commanded AO drive period to rational values.
    I'm mainly wondering if this problem can be corrected or if it's just a limitation of the method using two counters to create an on the fly counter output delay.
    Thanks,
    Steve

    John,
    I'm measuring the drift of the output signals (AO and Cntr1) on a daq board scanning at 5000 scans/s.
    The information you provided is helpful, I wasn't aware of the divide-down on the internal timebases.  Yes, I am specifying the frequency directly to Cntr0 so this may be coerced differently than the AO. 
    Where does one find these specifics on the board and various clocks?
    I've attached some sample code that may be of help to future users of this technique.  The sample code outputs a continuous regenerative buffered Analog Output waveform (board hardware timed).  Cntr1 is then configured in Frequency mode and triggers off of the AO.StartTrigger in order to synch the two signals.  Then Cntr1 is configured in High/Low mode and triggered off of the Cntr0.InternalOutput.  By changing the Cntr1 low time, I'm able to get an on the fly delayed output of Cntr1 relative to Cntr0 and hence the AO.
    If you have a daq board and you wire the AO and Cntr1 output signals into two analog input signals, you can see the drift when using irrational frequencies.  The sample code I provided only performs the output, so to see the signals you can simply create a continuous acquisition task in Max at 5Khz.
    Thanks for you time and support.
    Attachments:
    Delayed Counter Pulse.zip ‏137 KB

  • Problem with drawing Swingcomponents over the Videocomponent

    Hi there,
    I'm trying to draw a simple Swingcomponent over a running video - I read in the Forums for days - nothing helped. I don't know why it still don't work.
    LIGHTWEIGHT_RENDERER is already used
    JLayeredPane is already used
    Please help me - I don't what I can do anyway
    public class MySecondJMFApp extends JFrame implements ControllerListener{
         private Player player;
         public MySecondJMFApp(){
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              try {
                   Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));
                   player = Manager.createPlayer(new MediaLocator("file:C://video.mpg"));
                   player.addControllerListener(this);
                   player.realize();
              } catch (Exception e) {
                   e.printStackTrace();
         public synchronized void controllerUpdate(ControllerEvent e) {
              if(e instanceof RealizeCompleteEvent){
                   this.setBounds(0, 0, 800, 600);
                   this.setLocation(0,0);
                   JLayeredPane layeredPane = new JLayeredPane();
                   layeredPane.setPreferredSize(this.getSize());
                   layeredPane.setLocation(0,0);
                   this.add(layeredPane);
                   Component video = player.getVisualComponent();
                   video.setLocation(0, 0);
                   video.setSize(this.getSize());
                   JLabel label = new JLabel("THIS IS A RED TEXT");
                   label.setForeground(Color.red);
                   label.setOpaque(false);               
                   label.setLocation(0, 0);
                   label.setSize(this.getSize());
    //also tryed     label.setSize(this.getSize().width + 1, this.getSize().height + 1);
                   layeredPane.add(video, new Integer(1));
                   layeredPane.add(label, new Integer(10));
                   player.start();
                   this.setVisible(true);
         public static void main(String args[]){
              MyFirstJMFApp jmf = new MyFirstJMFApp();
    }

    Hi there,
    I solved the problem by myself :-)
    I read the API-Documentation again and again until I recognized the little "try" in "JMF trys to create a lightweigt Component". So I tried some other videos and realized - this Code is definitly working if JMF is able to create a lightweigth Component. In some cases I saw the red text - in other cases not.
    Good luck, if you have the same problem like I got ;-)

  • How to change the frequency of pulse train on the fly using an array of values?

    Hi all!
    First I want to thank U for the great job you are doing for this forum.
    Iam still busy trying to control a stepper motor, by sending pulses from my E-series 6024 to a compumotor s6- stepper Driver. I've managed to get it working. I desperately need to control the motor using the values from an array. I believe we can use two approaches for that:
    1st - I can get an array of the "numbers of pulses". Each element must run for 10 milliseconds. Using that we can calculate the array of frequencies to send the number of pulses within 10 milliseconds for each specific element. Could we use the arrays of "number of pulses" and frequencies in a "finite pulse train " and up
    date with each element every 10 millisecond?
    2nd - Or Could we use of the frequency array in a "continuous pulse train vi" and update it every 10 milliseconds?
    Please note that I must use the values as they are.
    Can someone please built a good example for me? Your help will be appreciated.
    Regards
    Chris
    Attachments:
    number_of_steps.txt ‏17 KB
    frequency.txt ‏15 KB

    Tiano,
    I will try to better explain the paragraph on LabVIEW. The original paragraph reads ...
    "While in a loop for continuous pulse train generation, make two calls to Counter Set Attribute.vi to set the values for "pulse spec 1" (constant 14) and "pulse spec 2" (constant 15). Following these calls you would make a call to Counter Control.vi with the control code set to "switch cycle" (constant 7). The attached LabVIEW programs demonstrate this flow."
    You can make two calls to Counter Set Attribute or you can make a call to Set Pulse Specs which, if you open this VI, you will see that it is just making two calls to Counter Set Attribute. What you are doing with the Counter Set Attribute VIs is setting two registers called "pulse s
    pec 1" and "pulse spec 2". These two registers are used to configure the frequency and duty cycle of your output frequency.
    The example program which is attached to this Knowledge Base demonstrates how to change the frequency of a continuous generation on the fly. Why continuous? Because changing the frequency of a finite train would be easy. When the train completes it's finite generation you would just change the frequency and run a finite train again. You would not care about the time delay due to reconfiguration of the counter.
    If you would like to change the frequency of the pulse train using a knob, this functionality will have to be added in the while loop. The while loop will be continuously checking for the new value of the knob and using the knob value to set the pulse specs.
    LabVIEW is a language, and as with learning all new languages (spoken or programatic) there is a lot of learning to be accomplished. The great thing is that LabVIEW is much easier than mo
    st languages and the learning curve should be much smaller. Don't fret, you'll be an expert before you know it. Especially since you're tackling a challenging first project.
    Regards,
    Justin Britten

  • Is there a way to add images to the collection used in Photomerge Style Match?

    When one uses the menu: Enhance->Photomerge® Style Match, there will be six images displayed to choose from. The path to them is (Mac):
    /Application/Contents/Resources/models/ While this menu is only available in Expert mode, you end up in Guided when you choose it. I assume, therefore, that there is actually an Action or at least a script.
    Simply adding an image wouldn't work, which I confirmed. Even rebuilding the MediaDatabase.db3 didn't help. But there must be more than just the simple jpeg that the app uses to perform the effect... or maybe not! ;-) All I'd like to know is if there is a way to add images to the list of choices.
    Thanks!

    What version of photoshop elements and mac os x are you using?
    Once your in the Style match screen you add images using the Green Plus button
    (the screenshot is from photoshop elements 12)

  • How to create reports online on the fly using meta-data.

    We have dataset and blank report. How can I create report design on the fly ? so that it will able to display report dataset.
    Can someone tell me it is possible or not ? or some reference links....

    Hello,
    This can be certainly done by executing a script written using Report Application Server (RAS) SDK.
    Please refer the link : [http://devlibrary.businessobjects.com|http://devlibrary.businessobjects.com] for detailed documentation on the usage of RAS SDK.
    Regards,
    Chinmay Athavale
    Edited by: Chinmay1009 on Jul 27, 2010 3:46 PM

  • I have a canon 60D and I'm trying to view images on the Ipad using the sd reader but no luck. Any help or ideas?

    I have a Canon 60D and I am unable to view or transfer photos to the Ipad using the SD Card reader. I have been able to view images with a Canon T3i. Are there certain settings I need to set on the 60d or should it work automatically? anythoughts or ideas? thanks

    Are the photo's you're trying to view/download in Raw?  I've had difficulty downloading Raw files, but have had no issues downloading JPEG files. Also, check a setting in your Canon, called communication.  From what I've read (I'm a Nikon D5100 guy myself), communication needs to be set to PTP, not normal.  I'm not sure how that will help if the pictures are already encoded?
    Well scratch what I've written.  I just googled the 60D and supposedly, JPEG and Raw are supposed to transfer through the SD card reader easily.  So, I'm clueless.  Sorry.......
    Message was edited by: rbrylawski

Maybe you are looking for

  • "Media Services Are Not Available"

    I'm new...trying to get my photos off of my Blackberry Curve 8520 , and put some music on my Blackberry. I just installed the Blackberry Desktop Software.  On my Blackberry, under Options -> Memory I have Mass Storage Mode Support set to On, and Auto

  • Video Podcasts Not Syncing From my iPad Mini to iTunes for Windows

    Hello all.  I have the iPad Mini, and recently have been downloading my Podcasts there. It occurred to me that in case something happens to my iPad, I should have my Podcasts backed up to my computer.  So, i downloaded iTunes for Windows on my comput

  • How to configure StorEdge 3510 as a SAN?

    Hi all, just joined! We've got a StorEdge 3510 set up as a DAS (private loop mode) connected to three servers. We've gone through hell and high water getting things configured (firmware upgrades were particularly troublesome), but now that we've got

  • Error in creating purchase order/ requisition/ quotation..

    Hi techies, I amunable to create a po and getting an error message as below. I tried ob08, ob07, obbs commands but of no use... can anyone please guide me....thanks in advance Ambiguous EUR/INR exchange rate relations Message no. SG028 Diagnosis The

  • FUJiFILM X-S1

    I have noticed that Aperture 3 only supports 4 cameras from FUJiFILM. I would like to buy the X-S1, but would have to think very carefully if it does not become one of the cameras that Aperture support. Does anyone have any experience with a X-S1?