This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes write pdf files whith servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Reply locked New topic

write pdf files whith servlets

bruno martins

Joined: Oct 28, 2003
Posts: 8
hi, i can�t display my pdf file whith this code:
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;
import java.sql.*;
public class testepdf extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String driver = "";
String url = "jdbc:mysql://sb/cmv?user=amd&&password=123";
String n1_ = "";

Connection con1;
Statement sta1;

String sql1 = "SELECT * FROM files";
PrintWriter out = response.getWriter();

try {
sta1 = con1.createStatement();

ResultSet rs = sta1.executeQuery(sql1);

"inline; filename=\"Acta.pdf\"");;

Blob blob = rs.getBlob(3);

if (blob != null)
int iLen = (int)blob.length();
ByteArrayOutputStream output = new ByteArrayOutputStream(iLen);
output.write(blob.getBytes(1, iLen), 0, iLen);



catch(java.lang.ClassNotFoundException e) {
out.println("ERRO na ClassNotFound: " + e.getMessage());

catch(SQLException ex) {
out.println("ERRO na ligacao :" + ex.getMessage());
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30353

So you are trying to display the first file in the datbase (even if the query returns more than one) and the file is in the third column in PDF format?
What error are you getting?

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61066

bruno, please do not cross-post the same question in multiple forums. Please continue any discussion here,

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
subject: write pdf files whith servlets