1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
Connection conn = null;
ServletOutputStream out = null;
try
{
int id_application=Integer.parseInt(request.getParameter("app"));
int numPage=Integer.parseInt(request.getParameter("page"));
String login_bdd = "somobile";
String password_bdd = "somobile2009";
String url = "jdbc:mysql://78.153.253.106:3306/schneider_final";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, login_bdd, password_bdd);
java.sql.Statement stmt = conn.createStatement();
java.sql.ResultSet rs = stmt.executeQuery("select * from application where id_application="+id_application);
if (rs==null)
return;
rs.next();
String filename=rs.getString("file");
conn.close();
FileInputStream in = null;
File f = new File(filename);
response.addHeader("Refresh", "1; /MainMyApplications1.jsp?page="+numPage);
response.addHeader("Content-disposition", "attachment; filename=" +f.getName());
out = response.getOutputStream();
in=new FileInputStream(f);
int b;
while ((b=in.read())!=-1)
{
out.write(b);
}
in.close();
out.flush();
/*response.setHeader("Cache-Control", "no-cache");
File f=new File(filename);
response.addHeader("Content-disposition", "attachment; filename=" +f.getName());
ServletOutputStream out = response.getOutputStream();
FileInputStream in=new FileInputStream(f);
int b;
while ((b=in.read())!=-1)
{
out.write(b);
}
in.close();
out.close();
RequestDispatcher rd = getServletContext().getRequestDispatcher("/MainMyApplications1.jsp?page="+numPage);
rd.forward(request, response);*/
}
catch(Exception e)
{ }
finally
{
if (out != null) out.close();
}
} |
Partager