Hi,
Yes, the servlet calls to jsp. The servlet read the database and it
stores the information in astrRdoAnalisis variable and then send this
variable to the jsp. is correct?
the connection declaration is before the try.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
the SERVLET has the next code:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.io.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ViewRdoAnalyzedFile extends HttpServlet{
public boolean fncVerFicheroAnalizado ( HttpServletRequest request,
HttpServletResponse response) {
String bd = "orcl";
String usuario = "alex14";
String password = "alex14";
String url = "jdbc
racle:thin
196.154.4.189:1521:"+bd;
Connection conn = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url,usuario,password);
String strCod_analisis = (String)
request.getAttribute("analisis");
int intCod_analisis =
Integer.parseInt(strCod_analisis);
Statement stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rsRdosAnalisis = stmt.executeQuery ("SELECT
NUM_MUTA, CAL_MUTA, CAL_NOMBRE, POLI, OUT, ROUND(X,2) X, ROUND(Y,2) Y
FROM tablasfg WHERE codigo = " + intCod_analisis );
boolean blnUltimoRdos = rsRdosAnalisis.last();
int intContadorRegistrosRdos = rsRdosAnalisis.getRow();
rsRdosAnalisis.beforeFirst();
String [][] astrRdoAnalisis = new
String[intContadorRegistrosRdos][11];
String strNumMutation;
String strCalMutNombre;
String strCalMutado;
String strPolimorfismo;
String strOutRank;
String strX;
String strY;
while(rsRdosAnalisis.next()){
strNumMutation = rsRdosAnalisis.getString("NUM_MUTA");
strCalMutado = rsRdosAnalisis.getString("CAL_MUTA");
strCalMutNombre = rsRdosAnalisis.getString("CAL_NOMBRE");
strPolimorfismo = rsRdosAnalisis.getString("POLI");
strOutRank = rsRdosAnalisis.getString("OUT");
strX = rsRdosAnalisis.getString("X");
strY = rsRdosAnalisis.getString("Y");
astrRdoAnalisis
[0] = strCalMutNombre;
astrRdoAnalisis[1] = strCalMutado;
astrRdoAnalisis[2] = strPolimorfismo;
astrRdoAnalisis[3] = strOutRank;
astrRdoAnalisis[4] = strX;
astrRdoAnalisis[5] = strY;
i++;
}
rsRdosAnalisis.close();
conn.close();
request.setAttribute("astrRdoAnalisis", astrRdoAnalisis);
RequestDispatcher rd =
request.getRequestDispatcher("/analyz.jsp");
rd.forward(request,response);
return true;
} // end try
catch(Exception ex) {
return false;
}
} //end de la funcion
public void doPost(HttpServletRequest request,HttpServletResponse
response)
throws ServletException,IOException{
boolean blnMostrar = fncVerFicheroAnalizado( request,
response);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
the JSP (analyz.jsp) has the next code::
////////////////////////////////////////////////////////////////////////////////////////////////
<%@page contentType="application/vnd.ms-excel"%>
<%@ page language="java" import="java.io.*"%>
THE RESULT ARE:
<%
String[][] astrRdoAnalisis = (String[][])
request.getAttribute("astrRdoAnalisis");
for (int i=0; i<astrRdoAnalisis.length; i++) {
out.write(astrRdoAnalisis[0] + "\t" );
out.write(astrRdoAnalisis[1] + "\t" );
out.write(astrRdoAnalisis[2] + "\t" );
out.write(astrRdoAnalisis[3] + "\t" );
out.write(astrRdoAnalisis[4] + "\t" );
out.write(astrRdoAnalisis[5] + "\t" );
out.write("\n");
}
%>