nikita.chandra 0 Junior Poster in Training

Hi all!
here i m posting my Servlet page code by using which i retrieve blob data from mysql website, but my problem is that i have to display this data to a textarea on other jsp page.

Anyone can help please, its very urgent....

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.chatekids;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 *
 * @author Nikita Chandra
 */
public class SelectPageContent extends HttpServlet {


    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

         HttpSession session = request.getSession(true);
         String sessionSelectedPage=(String)session.getAttribute("page");
        out.println("<h3>SelectPage Servlet</h3>");
        out.println("Selected Page = " +sessionSelectedPage);

        Connection con= null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        String strQuery = "SELECT Contents FROM Pages WHERE PageName='"+sessionSelectedPage+"'";

          con = (Connection) ConnectionClass.connection();
         InputStream page;
        try {

              pstmt = con.prepareStatement(strQuery);
              rs = pstmt.executeQuery();
              while(rs.next()){

                 

                  Blob content = rs.getBlob(1);
                  byte[] bytearray = new byte[1048576];
                  int size=0;
                  page = rs.getBinaryStream(1);
                  response.reset();
                  //response.setContentType("/home/sai13/PROJECTS/ChateKids/web/.jsp");
                  while((size=page.read(bytearray))!= -1 ){
                  response.getOutputStream().write(bytearray,0,size);

                  }
              }
           
     
        }
        catch(Exception e){

            System.out.println("Exception in parent Try block" + e);

        }
        finally{

            
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}