Home Answers Viewqa JSP-Servlet jsp code problem

 
 


jegan
jsp code problem
2 Answer(s)      3 years and 3 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

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 Pages:
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
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  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 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, 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 - 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 - 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
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
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
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
Code Problem - Struts
Code Problem  i want to insert multiple row values (from html table which is in jsp) into oracle database using struts.for example oracle table contains 3 fields as sub1,sub2,sub3.html table contains 10 rows of sub1,sub2,sub3
Code Problem - Struts
Code Problem  Sir, am using struts for my application.i want to uses session variable value in action class to send that values as parameter... function which uses userid and then forwards result to jsp page based on flag
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
Hibernate code problem - Hibernate
Hibernate code problem  Hai, iam working on simple login application.... Please find my src code here... ----------------controller Layer... is my spring-servlet.xml----------------- .jsp
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
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
problem in jsp programming - JSP-Servlet
problem in jsp programming  Write a JSP program which displays... branches of a retail company.   Hi friend, Code to help in solving the problem : Connection with mysql database
Problem in my code - Development process
Problem in my code  Plz go thru this code. I want to check login... executing code am getting 404 error User Name Password... Friend, It seems that the jsp file you are executing or you are calling
Session Problem in JSP - JSP-Servlet
normally from Remote machine by only writing JSP code.  Hi friend...Session Problem in JSP  I have developed a online feedback form in JSP platform. I have created normal session in JSP page. It is running in my
jsp usebean problem - Struts
popupwindow jsp below code run.. ...here iam getting the problem..in the below...jsp usebean problem   --Select... jsp
jsp code - JSP-Servlet
jsp code  I need code for bar charts using jsp. I searched some code but they are contain some of their own packages. Please give me asimple code... friend, Code to solve the problem : Thanks
logout problem?? - JSP-Servlet
logout problem??  sir, the logout code which u have send is not the proper solution coz,by using this code the browser get closed which shuold.../Logout.shtml http://www.roseindia.net/jsp/loginstatus.shtml Thanks
logout problem.. - JSP-Servlet
done in the code i have used session object in project's servlet and jsp...logout problem..  hi... first of all thanks for ur... but their is some problem with the the logout,i m not able to logout when
Jsp ,Servlet Problem - JSP-Servlet
Jsp ,Servlet Problem  hi, m new to jsp n Servlet. i really find ur... with oracle. it worked wonders. now i m starting jsp n servlet learning.. pls... to execute a servlet code on tomcat server... Thanking u... Santosh  
JSP Code - JSP-Servlet
JSP Code  Hi, Do we have a datagrid equivalent concept in JSP? If so, then please help me to find the solution of the problem. Its Urgent..., Please visit the following links: http://www.roseindia.net/jsp/data-grid.shtml
coding problem - JSP-Servlet
coding problem  Dear sir i m very new to JSP .I am using two...' keyword in the combobox to call the function in javascript. the following code may be helpful for u. length size js code: function
resultset problem - JSP-Servlet
resultset problem  hi I have one problem with resultset? ResultSet rs=st.execute("select subjname,staffname from staffdetails"); while...?  Hi Friend, We are providing you a sample code. It will be helpful
Statistical charts in JSP - problem
Statistical charts in JSP - problem  hey! i get this error when i run the code (with slight changes in query)! HTTP Status 500 - type... org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred
JSP run problem
JSP run problem  type Exception report message description... this request. exception org.apache.jasper.JasperException: Exception in JSP...) root cause java.lang.NullPointerException org.apache.jsp.bb_jsp
Array problem - JSP-Servlet
.. Bur my problem is that if the pop up window contains only 1 record... is selected.. Why? I am using the following code: function trim
arraylist problem - JSP-Servlet
my code once again only in which i m facing the problem. /* * To change... { String code=""; code=(String)session.getAttribute("code"); System.out.println("value
Radio Button Problem in jsp.
Radio Button Problem in jsp.  I have a small doubt in my application... the following code: 1)form.jsp: <%@page import="java.sql.*"%> <html> <... radio button values from jsp to action using javascript
jsp and bean problem
jsp and bean problem  Hi i have the following jsp code... Can you plz help me in separating the code to bean? I'm new to bean and need it for my..._Code; String v_QtL; String v_Large; String v_Haut
arraylist problem - JSP-Servlet
arraylist problem  in my following code i have used a condition... the first row. i m new to java. so i have messed up the code. but please... { String code=""; code=(String)session.getAttribute("code
pagination problem - JSP-Servlet
(),my problem is that where i have to put & how to do pagination? my code
pagination problem - JSP-Servlet
(),my problem is that where i have to put & how to do pagination? my code
ArrayList problem - JSP-Servlet
ArrayList problem  Hi, How can I add elements of an ArrayList to HTML combobox or list in java? Hi, You can use the following code: Array List Example  Hi,You can use the following code:<!DOCTYPE HTML PUBLIC "
JSP Code - JSP-Servlet
JSP Code  Hi, I have a problem in limiting the number of row... to display only 10 records per pages in jsp, then how can i achieve this concept... Rai.  Hi Friend, Try the following code: Pagination
Problem with cookies
Problem with cookies  Hello All, i need jsp code for RememberMe module of login. i am facing problem with cookies. so please if any one could guide me please help and provide mme the exact code.   Please visit
Problem in Jsp and database - Development process
Problem in Jsp and database  Hi, How can I reterive values from... the following code: step1) Create databaseTable.jsp: display data from the table using jsp First Name: Last Name: Address
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
jsp logout code
jsp logout code  hello sir, im doing jsp project, i have implemented the session code of jsp. session.invalidate(). but its not working. can u tell me what may be the problem. OR if possible pls send me the proper code
Problem in record viewing in jsp - JSP-Servlet
it but when i rewrite that link one time it is working. this is my code in jsp page...Problem in record viewing in jsp  hai i have developed the application using jsp,servlets in eclipse ide i have to insert,delete,update and view
jsp code error - JSP-Servlet
jsp code error  hello, is anyone here who can solve my problem. what happen experts where r u? r u not able to do

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.