Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet jsp code problem
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


jegan
jsp code problem
2 Answer(s)      4 years and 7 months ago
Posted in : JSP-Servlet


hi, I am going to execute the following code which has been given your jsp tutorial.

retrive_image.jsp:

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>

<% // declare a connection by using Connection interface
Connection connection = null;
/* Create string of connection url within specified format with machine
name, port number and database name. Here machine name id localhost
and database name is mahendra. */
//String connectionURL = "jdbc:mysql://localhost:3306/mahendra";
/*declare a resultSet that works as a table resulted by execute a specified
sql query. */
ResultSet rs = null;
// Declare statement.
PreparedStatement psmnt = null;
// declare InputStream object to store binary stream of given image.
InputStream sImage;
try {
// Load JDBC driver "com.mysql.jdbc.Driver"
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
/* Create a connection by using getConnection() method that takes
parameters of string type connection url, user name and password to
connect to database. */
connection = DriverManager.getConnection("jdbc:odbc:jegan");
/* prepareStatement() is used for create statement object that is
used for sending sql statements to the specified database. */
psmnt = connection.prepareStatement("SELECT image FROM test.save_image WHERE id = ?");
psmnt.setString(1, "1001"); // here integer number '1001' is image id from the table
rs = psmnt.executeQuery();
if(rs.next()) {
byte[] bytearray = new byte[1048576];
int size=0;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
while((size=sImage.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
}
}
}
catch(Exception ex){
out.println("error :"+ex);
}
finally {
// close all the connections.
rs.close();
psmnt.close();
connection.close();
}
%>

but while I try to execute the code it gives the following error message in the tomcat server. plz help me to run this code........

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

root cause

java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.catalina.connector.Response.getWriter(Response.java:610)
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:188)
org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118)
org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77)
org.apache.jsp.retriveimage_jsp._jspService(retriveimage_jsp.java:115)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
Apache Tomcat/6.0.20


Advertisement
View Answers

March 8, 2010 at 2:47 PM


Hi Friend,

Try the following code:

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>

<%

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:odbc:access");
Statement st1=con.createStatement();
ResultSet rs1 = st1.executeQuery("select image from Image where ID=1");
String imgLen="";
if(rs1.next()){
imgLen = rs1.getString(1);
System.out.println(imgLen.length());
}
rs1 = st1.executeQuery("select image from Image where ID=1");
if(rs1.next()){
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs1.getBinaryStream(1);
int index=readImg.read(rb, 0, len);
System.out.println("index"+index);
st1.close();
response.reset();
response.setContentType("image/jpg");
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();
}
}
catch (Exception e){
e.printStackTrace();
}

%>

Thanks


November 1, 2012 at 2:25 PM


hi friend is this code works only for the sun data base?



Related Tutorials/Questions & Answers:
jsp code problem - JSP-Servlet
jsp code problem  Hi, I have employee details form in jsp. After... have a problem with open the next form. plz, help me. thanks,  Hi friend, Please give me detail and send me error code page. Please
code for this problem - JSP-Servlet
code for this problem   i have buttom submit .It is working with single click.Suppose if i am At the same time clicking(parallel) twise second request will be stoped until process the proces first requst and terminate
Advertisements
JSP code problem - JSP-Servlet
JSP code problem  HI.. I have a DB2 stored procedure wich return a result set. I have made a report basing on this procedure using Crystal Reports. How to pass parameters to this procedure with java code in a JSP page
Jsp Code Problem - JSP-Servlet
Jsp Code Problem  I use DocType in my Jsp Page. The Links are not functioned after Applying the DocType. Could you tell me any way to activate the link. Thank You.   Hi Friend, Please send your code. Thanks
jsp code problem - JSP-Servlet
jsp code problem  i want to make the bill from the barcode. how do i convert a barcode into a decimal number
JSP code problem - JSP-Servlet
JSP code problem  Hi friends, I used the following code... is the code: Display file upload form to the user...: <% //to get the content type information from JSP
jsp code problem - JSP-Servlet
jsp code problem  hi, I am going to execute the following code which has been given your jsp tutorial. retrive_image.jsp: but while I try to execute the code it gives the following error message in the tomcat
jsp code problem - Java Beginners
jsp code problem  Hi, I have a problem with else part. It did not show the message box when the result set is null. plz, help me. thank u in advance
javascript code problem - JSP-Servlet
; "> in above code which is jsp and struts form bean...javascript code problem  Thanks for sending answer.but actually what u send is not my actual requirement.first look this code. Subject
servlet code problem - JSP-Servlet
servlet code problem  This is my JSP code index.jsp Sync Data Sync Data Please use the following input box to upload file or enter... showing null value and i downloaded this code from net but this also not showing
servlet code problem - JSP-Servlet
servlet code problem  This is my JSP code index.jsp Sync Data Sync Data Please use the following input box to upload file or enter the user id in input box directly. Upload File: Enter UserId
Date Time Problem In Jsp code - Development process
Date Time Problem In Jsp code  Hi Friends, By using this code , am storing date and time into msaccess database. But while retriving i want to get same date and time .send me code for that. SimpleDateFormat
Java Script Code Problem - JSP-Servlet
Java Script Code Problem  how to concatenate html table values(there are 3 rows,each row contains 3 fields) into variable and display it using javascript  Hi Friend, Try the following code: document.write
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration... RESEND THE CODE org.apache.jasper.JasperException: java.lang.NumberFormatException... in database as text and set the mobile field or telephone field as string in your code
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration... RESEND THE CODE org.apache.jasper.JasperException: java.lang.NumberFormatException... in database as text and set the mobile field or telephone field as string in your code
problem with code - Ajax
problem with code  hi friends i am sending a code in that when we select the countries states have to be selected by using only jsp in that we have to use ajax i wrote the code of jsp and the remaning code by using ajax
hibernate code problem - Hibernate
/selectclause.shtml If you have any problem this send me detail and source code...hibernate code problem  suppose i want to fetch a row from the table through a value which i got from the jsp page. how can i do it and iterate
jsp problem
jsp problem  problem:::::::: On JSP form ,when i insert data in text field........at that time action is perform and data is retriev from data base... (Exception e) { System.out.println(e); } %> 3)For the above code, we have
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
Jsp problem
Jsp problem  Hello friends.I want to share my jsp problem.I want to show all of my database(mysql) tables except two(user,manufacturer) in a jsp page.plssss help me
jsp problem
jsp problem  Hello Friends, I want to show one page for 5 seconds and after that i want to redirect the page to another URL
jsp problem
jsp problem  Hi every one plz give me answer for below question ASAP I created one JSP(used pre defined javascript in jsp to get rtf format in browser) which creats RTF Format in browser to enter data. MY question is after i
code problem:ajax - Ajax
code problem:ajax  Hi,I am using ajax to populate a select box.for this I am writing out.write("ONE"); like that.it runs fine in firefox.bt not in IE.Can anyone help me out this... thanks
Hibernate code problem - Hibernate
Hibernate code problem  Hi, This is Birendra Pradhan.I want... in the DAO.Can it be possibe. Please send some sample code.. thanks & Regards Birendra  Hi friend, For solving the problem visit
code problem - Java Beginners
code problem  Dear sir, my problem is that I've a string value if this String value has "quit" then output should be "bye". i want to make this program using SWITCH CASE statement. how to implement String value in Switch plz
code problem - Java Beginners
code problem  Dear sir, I'm havin a problem that suppose i've got... java script j2ee j2me sql plz help me to sort out this problem. thnx   Hi Friend, Please try the following sample code to solve your problem
jsp problem - JSP-Servlet
jsp problem  here is a code for Retrieving image from mysql database through jsp. but i cann't set size of image when it was display so what should... working but my problem is size of image. so can u just help?? code
jsp problem - JSP-Servlet
jsp problem  here is a code for Retrieving image from mysql database through jsp. but i cann't set size of image when it was display so what should... working but my problem is size of image. so can u just help?? code
code problem - Java Beginners
code problem  Dear sir, My problem is that i have some string value and in some case i want to remove all the value of this string, i tried this code- Response.str.clear(); but it shows some error called "response package
Advertisements
 

 

 

DMCA.com