Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2002
    Posts
    6

    Question Unanswered: Fail to display String and image in JSP

    I have written a JSP to display Blob image and String but the page can display image only. I have no idea what happen. Can anybody point out what is the problem? Please kindly provide sample page for my reference.

    <%@ page contentType="text/html;charset=gb2312"%>
    <%@ page import="oracle.jdbc.driver.OracleConnection,
    java.sql.DriverManager,
    java.sql.SQLException,
    java.sql.*,
    javax.sql.*,
    java.io.*,
    java.text.*,
    java.util.*;"%>
    <html>
    <head>
    </head>
    <body>
    <%
    response.setContentType("text/html;charset=gb2312");

    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String dbConnection2="jdbc: oracle:thin:@eai-dev:1523:VIS";
    Connection con2=DriverManager.getConnection(dbConnection2, "apps", "apps");

    Statement stmt2=con2.createStatement();
    ResultSet rs2=stmt2.executeQuery("select * from fnd_lobs where file_id=75258");
    if (rs2.next())
    {%><%=rs2.getString(1)%><br><%}
    }
    catch (SQLException e)
    {
    System.err.println (e) ;
    %>
    <%=e%>
    <%
    }


    // response.setContentType("image/jpeg");

    char c;
    byte [] b;
    int i=0;

    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String dbConnection="jdbc: oracle:thin:@eai-dev:1523:VIS";
    Connection con=DriverManager.getConnection(dbConnection, user, pwd);

    Statement stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery("select * from fnd_lobs where file_id=75258");
    if (rs.next())
    {
    ServletOutputStream sout = response.getOutputStream();
    InputStream in = rs.getBinaryStream("FILE_DATA");
    b = new byte[0x7a120];
    for(i = in.read(b); i != -1; )
    {
    sout.write(b);
    in.read(b);
    }
    sout.flush();
    sout.close();
    }
    }
    catch (SQLException e)
    {
    System.err.println (e) ;
    %>
    <%=e%>
    <%
    }
    %>
    </body>
    </html>

  2. #2
    Join Date
    Sep 2002
    Posts
    1

    Re: Fail to display String and image in JSP

    I think it can't display image and Strings in one page, because the page's content type must be one of "image/jpeg" or "text/html", can't be both.

    You can use 2 pages :

    showBoth.jsp
    <%
    // content type is "text/html"
    out.println("your strings");
    out.println("<img src='showImage.jsp?id=x'>");
    %>

    showImage.jsp
    <%
    // content type is "image/jpeg"
    // show image here
    %>
    Last edited by HouZhitao; 09-29-02 at 05:57.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •