Use jsp as image source

In php I have an option to say
<img src="gen_image.php">Here in the gen_image.php I set the content type as image/jpeg and use the gd library to generate a dynamic image.
This is used in various registration validations for dynamic image generation.
My question is can I do this using a jsp or a servlet. Wud help if you could submit the source code.

You do the same thing in the JSP page as you do in the PHP page, just with Java instead of PHP. There's no difference. Set the content type, send image data. You can generate an image using the java.awt.image.BufferedImage class, drawing on it's Graphics object, and exporting a JPEG or PNG file with the javax.imageio.ImageIO class
There is 1 caveat for JSP pages, which is you can't have newlines in the page before you send image data, which means you can't do this:
<%@ page language="Java" contentType="image/jpeg" %>
<%@ import="java.net.*;" %>
<%@ import="java.util.*;" %>
<%
// code to get image data.
%>but instead:
<%@ page language="Java" contentType="image/jpeg" %><%@ import="java.net.*;" %><%@ import="java.util.*;" %><%
// code to get image data.
%>Cuz the newlines are added between those <%%> blocks, so you need to avoid that. Which is generally why it's better to use servlets for that.

Similar Messages

  • Using Jsp upload Image

    I m using jdbc 2.0 . The image is stored in the LongRaw data type . Now without getbinarystream i want to get that data and display as an image. There is a oracle.jdbc.* package which provides getRaw() method .But i am facing problems in it . Can any one help me ? Please help me it is very urgent.

    You have to write file upload bean for that there are many resources in weg for that search in google

  • How can i upload a image file to server by using jsp or servlet.

    Hi,
    I m gurumoorthy. how can i upload a image file to server by using jsp or servlet without using third party API. pls anyone send me atleast outline of the source code.
    Pls send me anyone.
    Regards,
    Gurumoorthy.

    I'm not an applet programmer so I can't give you much advice there.
    If you want to stream the file from the server before it's entirely uploaded, then I don't believe you can treat it like a normal file. If you're just wanting to throw it up there and then listen to it, then you can treat it like a normal file.
    But again, I'm not entirely certain. You might be able to stream the start of the file from the server while you're still uploading the end of it, but it probably depends on what method you're using to do the transfer.

  • Use different "fx-border-image-source" for first tab and remaining tabs

    Hi,
    I'm using something like this
    .tab {
    -fx-padding: 0px 5px -2px 5px;
    -fx-background-insets: 0 -20 0 0;
    -fx-background-color: transparent;
    -fx-text-fill: #c4d8de;
    -fx-border-image-source: url("images/tab5.png");
    -fx-border-image-slice: 20 20 20 20 fill;
    -fx-border-image-width: 20 20 20 20;
    -fx-border-image-repeat: stretch;
    -fx-font-size: 22px;
    .tab:selected {
    -fx-border-image-source: url("images/tab-selected5.png");
    -fx-text-fill: #333333;
         -fx-background-color: red;*/
    to customize the tab appearance of a TabPane.
    That worked well. But I need to use a different set of images for just the first tab. Does anyone know a way to accomplish that?
    Thanks.

    How can I "fix up" the first tab of tab panes that are created after I "fixed up" the first tab of the initial tab pane?
    My app allows user to create new tab panes at any moment during program execution.Not easy to answer this one.
    The best answer would be to use structural pseudoclasses, but (as David points out), they are not yet implemented.
    The trick here is how to identify the first tab of each tab pane so that it can be styled separately from the other panes.
    Doing the styling without a dynamic lookup is preferrable to using a dynamic lookup (i.e. when the first tab is created give it a specific style, e.g. tab0).
    This is how the charts work, where they set style classes based on series of data, e.g. series0, series1 - this allows you to independently style each series of data.
    However the chart stuff has all of that built into the implementation, whereas the tabs don't. To achieve that you would likely need to go into the TabSkin code (http://openjdk.java.net/projects/openjfx/) find out where and how it generates the Tab nodes and write a custom tab skin or extension of the existing one which assigns a numeric style class to each new tab in a pane (e.g tab0, tab1, etc). In other words, not particularly easy if you are unfamilar with the tab skin implementation. You could log a javafx jira feature request to have those style classes set on tabs - file it here => http://javafx-jira.kenai.com.
    In the meantime a simple alternative is to use the dynamic lookup method in my previous post and a hack such that whenever you add a new tab pane to the scene you do something like the following:
    new Timeline(
      new KeyFrame(
        Duration.millis(50),
        new EventHandler<ActionEvent>() {
          @Override public void handle(ActionEvent arg0) {
            Node tab = newTabPane.lookup(".tab");
            if (tab != null) tab.getStyleClass().add("first-tab");
    ).play();The reason for the Timeline is that I don't really know at what stage the css layout pass is executed. I know that when you initially show the stage and then do a lookup, the css pass seems to have already been done and the lookup will work. But for something that is dynamically added or modified after the scene is displayed - I have no idea when the css layout pass occurs, other than it's some time in the future and not at the time that you add the tabPane to the scene. So, the Timeline introduces a short delay to (hopefully) give the css layout pass time to execute and allow the lookup to work (not return null). Not the best or most efficient solution, but should work for you.

  • 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

  • Display the images in excel using jsp

    Hi
    I am unable to display the images in excel using jsp. I can display the data. but cannot display the images. It is simply showing the icon without the image. Is there any way to display the images. Pls give some sample code to display the images in excel.
    Thanks in advance.

    Presumably whoever created the images in that Excel document just put links to somewhere on their hard drive. Those links don't mean anything when you put the document on somebody else's computer, which is what you are doing. At least, that is my guess.
    You could spend some time looking at the Excel file to see how the images were put in there. Or you could ask the person who put the images in there.

  • How to upload a image file using JSP

    hello to all.
    i am in the learning stage please help me to upload a image file
    using jsp. give the explanation to the code also if possible.
    thanks in advance
    sincerely
    Chezhian

    You may find the following articles useful for the JSP/Servlet part:
    Uploading files: http://balusc.blogspot.com/2007/11/multipartfilter.html
    Downloading files: http://balusc.blogspot.com/2007/07/fileservlet.html

  • Using Ternary operators to set image source

    Hi,
    I'm using JDeveloper llg, and have an ADF table, in one of the columns im trying to have just an image displayed.
    Using:
              <af:column width="16">
                         <img src="icons/bullet_green.png"
                                 height="16"
                                 width="16"/>
                </af:column>this works fine and the correct image is displayed. Is it possible to use an EL expression to determine which image should be displayed using a ternary operator? i have tried the following:
              <af:column width="16">
                            <img src="#{row.ServiceState == '100' ? 'icons/bullet_green.png' : 'icons/bullet_red.png'}"
                                 height="16"
                                 width="16"/>
              </af:column>however no image at all is now displayed when the application is run. Does anybody now how to fix this?
    Thanks in advance...

    One solution is to use an af:image instead of the normal img tag. Then put two af:image tags inside you af:column and set the visible attribute to your EL like:
    <af:column width="16">
    <af:image shortDesc="klassiert" source="icons/bullet_green.png" visible="#{row.ServiceState == '100'}" inlineStyle=" height:16px; width:16px;" />
    <af:image shortDesc="klassiert" source="icons/bullet_red.png" visible="#{row.ServiceState != '100'}" inlineStyle=" height:16px; width:16px;" />
    </af:column>Timo

  • How to retrieve image in BLOB in oracle database using JSP?

    do any one the method to view image in homepage using jsp from BLOB field in oracle database ?
    thx

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Bon BOn:
    do any one the method to view image in homepage using jsp from BLOB field in oracle database ?
    thx<HR></BLOCKQUOTE>
    I am using a servlet that retrieves the BLOB from the database, sets the MIME type and puts it in a stream. The code is :
    package TestQueryITM;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import java.net.*;
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.driver.OracleDriver;
    import oracle.jdbc.driver.*;
    public class MIMEServlet extends HttpServlet {
    DbConnect myDbBean = new DbConnect();
    int Id=6;
    String MIME ="plain/text";
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    public void doGet(HttpServletRequest req,HttpServletResponse res)
    throws ServletException, IOException
    try
    String content_type = new String();
    String filename = new String();
    // Load the Oracle JDBC driver:
    Class.forName("oracle.jdbc.driver.OracleDriver");
    // Connect to the database:
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@ORAVISION:1521:DEV","[username]", "[password]");
    // It's faster when auto commit is off:
    conn.setAutoCommit (false);
    // Create a Statement:
    Statement stmt = conn.createStatement ();
    try
    BLOB lob_loc = null;
    java.io.InputStream in = null;
    int pos = 0;
    int length = 0;
    OracleResultSet rset = (OracleResultSet) stmt.executeQuery (
    "SELECT text FROM test WHERE ID = "+Id);
    if (rset.next())
    lob_loc = ((OracleResultSet)rset).getBLOB(1);
    MIME=rset.getString(2);
    // File binaryFile = new File("C:/aantekeningen.doc");
    // FileInputStream in = new FileInputStream(binaryFile);
    in = lob_loc.getBinaryStream();
    // This loop fills the buf iteratively, retrieving data // from the InputStream:
    res.setContentType (application/pdf);
    res.setHeader ("Content-Disposition","attachement;filename=test.doc");
    ServletOutputStream op = res.getOutputStream ();
    byte[] buffer = new byte[32000];
    while ((in != null) && ((length = in.read(buffer)) != -1))
    // the data has already been read into buf
    System.out.println("Bytes read in: " +
    Integer.toString(length));
    op.write(buffer,0,length);
    op.flush();
    op.close ();
    in.close();
    stmt.close();
    conn.commit();
    conn.close();
    }catch (SQLException e)
    e.printStackTrace();
    }catch(Exception e)
    System.out.println("<BR>");
    e.printStackTrace();
    System.out.println("<BR>");
    public String getServletInfo() {
    return "TestQueryITM.MIMEServlet Information";
    null

  • Retrieve image from my sql database using jsp

    I want to retrieve image from my sql (blob type) & save it in given relative path in server .(using jsp and servlets)
    please give me some sample codes.

    PreparedStatement pst = null;
      ResultSet rs=null;
    pst = conn.prepareStatement("select image from imagedetails where imageid='"+imageid+"'");
    rs=pst.executeQuery();
    while(rs.next())
                                byte[] b=rs.getBytes("image");
                                FileOutputStream fos=new FileOutputStream("c://image.jpg");
                                fos.write(b);
                            } hi this the code to retrieve the image from DB and write to a file.

  • Uploading images in access database using jsp

    Hi, am using jsp with access database and want to upload as in a profile picture for any profile on the site[i mean depending on the user's convenience] ..
    I just have a code which helps select the image from the client's machine n gets its address..but then how to use it in a form or something so that it can be submitted and inserted in the database?
    Any idea? I d prefer not using servelet.. but if it just cannot be done without servelet then ok can suggest with that too.
    Here is the code of Browsing to obtain the picture:
    <form name=uploadForm action="uploadpic.jsp" method=post enctype="multipart/form-data" >     <input type="file" > <input type="submit" name="submit"  />     </form>

    silversurface wrote:
    Hi, am using jsp with access database and want to upload as in a profile picture for any profile on the site[i mean depending on the user's convenience] ..
    bad. Don't put business logic in JSP, and that includes accessing databases.
    Any idea? I d prefer not using servelet.. but if it just cannot be done without servelet then ok can suggest with that too.
    Don't put business logic in JSP. That's what servlets are for (and EJB).

  • Problems distributing application using Imaging Source USBCamera and Labview 2010 - Imaging Source sdk required?!

    Hi
    I've been having trouble with the Imaging Source camera we own when trying to build applications.
    Everything works perfectly on the dev PC with appropriate sdk installed.
    When I  move to building the application (no errors) and deploying it to another PC the activeX control used to interface with the camera does not appear.
    Instead I get 'Control could not be loaded' in red text where the control should be.
    As far as I can see the activeX component itself is correctly installed on the PC.
    If I install the IC Imaging Control sdk the application begins working correctly.
    If I uninstall the sdk from the dev PC I get the message about needing a license if I attempt to add the ActiveX control afresh to the program (via the activeX container)
    I've posted on the Imaging Source forums and they suggested I try here.
    ORIGINAL POST ON IMAGING SOURCE FORUMS:
    I'm using a DMK 41BU02 with labview 2010 + IC Labview extension.
    The activeX interface for the camera works fine until I deploy it to a PC that does not have the IC Control software installed.
    All I see is a 'Control could not be loaded' message where the activeX box should be.
    I've installed VB6 redistributable to the client PC so I know the activeX workings should be present on the PC.
    If I install IC Control onto the PC the program starts working correctly!
    Has anyone compiled software with Labview 2010 successfully?
    Is there a trick when creating the application/installer spec?
    Thanks in advance
    Dan Acres
    REPLY
    This is correct. I suppose, the LabVIEW setup creating system does not automatically add the used DLL in the "user.lib" directory of your LabVIEW installation path. What does the LabVIEW support say about this, especially in relation to ActiveX controls, that use the Microsoft licensing mechanism?
    The dll he mentions is packaged into the support folder in the application spec.
    I have also manually copied the dll into the location referenced by the software (Labview 2010\user.lib\xxxx.dll).
    This made no difference.
    I've got no experience building these kind of thing into applications so I cannot tell if it is caused by a mistake I've made or Labview or if the Imaging Source softwares have done something wrong.
    Many thanks in Advance
    Dan Acres

    Dan,
    I think I might have a solution for you and others who need to include the imaging source active-x control in a deployed executable program.
    I solved this problem by creating a project that included the dlls and .ocx files required for the Active X Control (these files are in a folder is created once the IC Software is installed C:\Program Files (x86)\Common Files\IC Imaging Control 3.2) and an executable that registers the Active X Control after the main program is installed.
    The simple vi that registered the .ocx control for me upon install of my LabVIEW executable was called RegisterActiveXCtrl.vi. All it does is calls the regsvr32 with the path of my .ocx file.
    I bundled my main program PCDemo_Stratom.exe and RegICActiveX.exe into an installer and set the option to run RegICActiveX.exe at the end of installation.
    The installer must be installed with administrator rights to get the RegICActiveX.exe regsvr32 call to work.
    Hope this helps you/others in the future!
    Dan A

  • HELP!!!!Display blob image using JSP

    Hi,
    I am trying to blob image using JSP but it did not display successfully.
    Can someone help, please?
    below are the codes snippet:
    <td>
    <img src="display_image.jsp?ID=<%=request.getParameter("ID") %>" width="115" border="0">
    </td>
    byte[] image_blob = details.getImageByteArray();
    response.setContentType("image/jpeg");
    //response.setContentType("image/gif");
    //BEGINNING OF SECTION TO DISPLAY IMAGE
    /*OutputStream fos = null;
    fos = response.getOutputStream();
    fos.write(image_blob, 0, image_blob.length);
    fos.flush();
    fos.close();*/
    java.io.FileOutputStream fos1 = new java.io.FileOutputStream("C:\\"+id+".jpg");
    fos1.write(image_blob);
    fos1.close();
    OutputStream o = response.getOutputStream();
    System.out.println("o");
    o.write(image_blob);
    System.out.println(image_blob);
    System.out.println("write image");

    Use Java Image or BufferedImage instead of obscure byte array for image data.
    Here's an example code for a JSP document:
    <%
    String wid = request.getParameter("percent");
    String cost = request.getParameter("suchi");
    response.reset(); //IMPORTANT !
    response.setContentType("image/jpeg");
    // for testing purpose
    if (wid == null) wid = "58";
    if (cost == null) cost = "3400";
    float dleng = Float.parseFloat(wid) * 2.6f;
    RenderedImage rimg = drawGraph(dleng);
    OutputStream os = response.getOutputStream();
    try{
      ImageIO.write(rimg, "jpg", os);
    catch(IOException e){
    os.flush();
    %>
    <%!
    public RenderedImage drawGraph(float barLength){
      final int w = 800;
      final int h = 18;
      final int x = 0;
      final int y = 0;
      BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
      Graphics2D g2 = img.createGraphics();
      Color c = new Color(Integer.parseInt("FF9999", 16));
      g2.setColor(Color.yellow);
      g2.fillRect(x, y, w, h);
      g2.setColor(c);
      g2.fillRect(x, y, (int)barLength, h);
      g2.dispose();
      return img;
    %>

  • How can I upload an image using JSP in database(MySQL)

    I have to develop an application in which users can register themselve by filling up thier information(name, address) etc along with their photo.
    Storing nam etc. is simple but i am unable to upload photo using JSP.

    Here are lot of examples: http://www.google.com/search?q=jsp+file+upload
    Or if you actually have implemented something which doesn't work as expected, then please ask specific questions.

  • Which approach to use for resizing image

    There are two ways of resizing images as I know:
    1. image.getScaledInstance(width,height,hint);
    Using hint like Image.SCALE_AREA_AVERAGING gives somehwat satisfactory resizing.
    2. static BufferedImage resize(GraphicsConfiguration gc, BufferedImage source, int w, int h, Object hintValue) {
    BufferedImage result = gc.createCompatibleImage(w, h, source.getTransparency());
    Graphics2D g2 = result.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hintValue);
    double sx = (double) w / source.getWidth(), sy = (double) h / source.getHeight();
    g2.drawRenderedImage(source, AffineTransform.getScaleInstance(sx, sy));
    g2.dispose();
    return result;
    where the hint passed is RenderingHints.VALUE_INTERPOLATION_BILINEAR ;
    Now which of the two method method should I use-using image.getScaledInstance() or using AffineTranform ? opr is there any other way which is faster but provides good result?
    i am creating an image editor, so the GUI dialog will have oprtion to choose the algorithm. I want the method which provides better result yet faster.
    Tanveer

    http://forum.java.sun.com/thread.jsp?forum=20&thread=522483

Maybe you are looking for

  • How can i add music to my iPod 4 without removing the music that's already there ?

    I want more music on my iPod 4 , and my dad has a lot of music that I like . We have one of those computers where there can be more than one user , so each of my family members have their own user account and they have different itunes and whatnot .

  • Power Outage - Apple Cinema Not Turning On

    Hello, We had a power outage and after electricity came back I tried to turn on my computer. The G4 starts but somehow my Apple Cinema does not come on (the light does not turn on). Any suggestions what I should do to fix it? Thank you in advance for

  • Job in Singapore: Web Developer

    Web Developer (Permanent) Job Scopes: Maintaining current in-house applications and systems Assisting in system and infrastructure administration and support Design and build hardware infrastructure when needed Design database based on business requi

  • Use of semantic groups to aggregate data

    In a number of threads - e.g. Semantic Groups in DTP it is stated that you cannot use semantic groups to aggregate data. In others, there are statements that this is only for handling the error stack. This I find puzzling, as the SAP Help says: +Choo

  • Previous version RH to RH8?

    I've got a previous version of RH which I want to update to RH8. I get 2 errors: Error in reading RH FRameSTyle Mappings .apj and Open project cancelled or app was unable to load data base for .cpd file. I've deleted .cpd file. Any suggestions for ho