elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


  Mostrar Temas
Páginas: 1 2 3 4 5 [6] 7 8 9
51  Programación / Desarrollo Web / JQuery imagen de espera hasta completar respuesta[SOLUCIONADO] en: 18 Noviembre 2011, 14:41 pm
Estimados, tengo un pequeño problema, lo que pasa es que estoy trabajando con JSF y debo hacer que al apretar un click, salga un gif de espera y solo se oculte al cargar la pagina que debe ir. La cosa es que no deseo colocar a que pagina va desde jquery porque eso lo hace solo.

posteo codigo.


Código
  1.  
  2. <script type="text/javascript" src="/resources/javascript/jquery-1.3.2.min.js"/>
  3.  
  4. <script>
  5. $(document).ready(function(){
  6.  
  7.  $(".funciona").click(function(evento){ //Escucho el styleclass funciona
  8. //   var valorAlmacenado = "#{menuBackingMB.vistaActual}" //pagina actual
  9. evento.preventDefault();
  10. $("#cargando").css("display", "block");
  11. /*Aca deberia esperar a que se carge el contenido de ese valor almacenado para ocultar la imagen, pero la cosa es que quiero hacerlo de otra forma, que simplemente escuche que la respuesta del boton se completo y ahi ocultar la imagen, se puede hacer esto? */
  12. $("#contenidoform\\:contenido").load( function(){
  13. $("#cargando").css("display", "none"); //aqui oculto la imagen
  14.  
  15. }).hide();
  16. });
  17. });
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. </script>
  25.  

Solucion : El codigo esta bien, el problema es donde estaba puesto el div xD al renderizar la pagina se escribia el div de la imagen y entonces se desaparecia antes de lo debido.
52  Foros Generales / Foro Libre / Salvemos internet [URGENTE] en: 17 Noviembre 2011, 15:49 pm
http://www.avaaz.org/es/save_the_internet/?cl=1398489342&v=11169

Lean y firmen por favor, es un movimiento social contra las violaciones a nuestros derechos e injusticias, en este caso se pide firmar contra la censura de internet!

Resumen

Publicado: 15 Noviembre 2011
En estos momentos, el Congreso norteamericano está debatiendo una ley que le daría a EE.UU poder para censurar Internet a nivel mundial, ¡creando una lista negra que podría incluir a YouTube, WikiLeaks, e incluso a grupos como Avaaz!
53  Foros Generales / Foro Libre / Duda existencial xD en: 14 Noviembre 2011, 22:00 pm
Tengo una duda, veo a mucha gente que se esfuerza programando en batch, un lenguaje scripting arcaico y añejo y el cual no le veo utilidad habiendo tantos lenguajes de sintaxis decente y mucho mas poderoso que eso. Porque hay gente que se molesta en programar en eso? , no me digan que es para aprender porque omitan por favor esa respuesta, ok, pueden aprender lo que quieran, pero porque esforzarse en hacer cosas que se pueden hacer mucho mas rapido y simple en otros lenguajes  :huh:
54  Programación / Java / Consulta ScreenShot de una ventana web en: 9 Noviembre 2011, 14:16 pm
Hola estimados, tengo un problema, necesito sacar un screenshot a la pagina que estoy visitando , la idea es esta:

Tengo un html de cartola y ese html lo tengo que pasar a pdf, ya lo hice y me quedo bien feo la conversion de html a pdf, asi que mi idea es :

sacar un pantallazo a la pagina con el boton exportar, esa imagen guardarla en el pdf y al exportar todo generar el pdf con el pantallazo del html generado, la cosa es que he intentado usar esa clase Robot para sacar el pantallazo y la cosa es que me sale una excepcion asumo que es porque no hay gui, como es una clase java que hace todo y es todo a nivel web (JSF) no me sale.


Si me dan cualquier pista, una mano, encantado estaría gracias de antemano.

///Datos////

Este es el erro que me sale :

Código
  1. GRAVE: java.awt.HeadlessException
  2.  

Este es el metodo

Código
  1.  
  2.  /*Testeo de screenshot*/
  3.  
  4.            Toolkit toolkit = Toolkit.getDefaultToolkit();
  5.            Dimension screenSize = toolkit.getScreenSize(); //En esta linea lanza la excepcion
  6.            Robot robot = new Robot();
  7.            Rectangle rectangle = new Rectangle(0, 0, screenSize.width - 15, screenSize.height);
  8.            BufferedImage image = robot.createScreenCapture(rectangle);
  9.            ImageIO.write(image, "jpg", new File("c:\\mmgg.jpg"));
  10.  
  11.            /*Fin testeo*/
  12.  
  13.  

Intente con esto y se me ve bien con el html de ejemplo, pero con el mio solo muestra texto =/
Código
  1.           //   file.write();
  2.  
  3.            document.close();
  4.            file.close();
  5. /* TESTING*/
  6.            String htmls = "<html>"
  7.                    + "<h1>:)</h1>"
  8.                    + "Hello World!<br>"
  9.                    + "<img src=\"http://img0.gmodules.com/ig/images/igoogle_logo_sm.png\">"
  10.                    + "</html>";
  11.  
  12.            JLabel label = new JLabel(html);
  13.            label.setSize(5000,5000);
  14.  
  15.            BufferedImage image = new BufferedImage(
  16.                    label.getWidth(), label.getHeight(),
  17.                    BufferedImage.TYPE_INT_ARGB);
  18.  
  19.            {
  20.                // paint the html to an image
  21.                Graphics g = image.getGraphics();
  22.                g.setColor(Color.BLACK);
  23.                label.paint(g);
  24.                g.dispose();
  25.            }
  26.  
  27.            // get the byte array of the image (as jpeg)
  28.            ByteArrayOutputStream baos = new ByteArrayOutputStream();
  29.            ImageIO.write(image, "jpg", baos);
  30.            byte[] bytes = baos.toByteArray();
  31.              ImageIO.write(image, "png", new File("C:/test.png"));
  32. /* FIN TESTING */
  33.  
Ignoren el tamaño del label  :xD
55  Programación / Java / Problema al crear excel [SOLUCIONADO] en: 4 Noviembre 2011, 16:50 pm
Estimados, tengo una aplicación que hice y quiero exportar a excel a partir de un arraylist, la cosa es que me crea el excel, lo bajo me abre con errores, se reinicia el office y automaticamente me lo repara y me lo abre bien, pero la cosa es que quiero que abra sin errores, adjunto metodo


Código
  1.  
  2.  
  3.    public void postProcessXLS() {
  4.        if (movimientos == null) {
  5.            cargaTablaDinamica();
  6.        }
  7.        System.out.println("Entre al metodo postProcess");
  8.  
  9.        //  HSSFWorkbook wb = (HSSFWorkbook) document;
  10.        HSSFWorkbook wb = new HSSFWorkbook();
  11.        HSSFSheet sheet = wb.createSheet("Movimientos");
  12.        // wb.setSheetName(0, "Ejemplo"); //Asignamos nombre a la hoja de calculo
  13.  
  14.     //   HSSFRow header = sheet.createRow(0);
  15.        HSSFRow fila = null;
  16.  
  17.  
  18.  
  19.        //HSSFRow fila = sheet.getRow(1);
  20.       /* Llenar las cosas*/
  21.        for (int i = 0; i < movimientos.size(); i++) {
  22.            fila = sheet.createRow(i);
  23.  
  24.            for (int j = 0; j < 5; j++) {
  25.                fila.createCell(j);
  26.  
  27.            }
  28.  
  29.         /*   fila.getCell(0).setCellValue("Fecha");
  30.             fila.getCell(1).setCellValue("Descripcion");
  31.             fila.getCell(2).setCellValue("Serie");
  32.             fila.getCell(3).setCellValue("Monto");
  33.             fila.getCell(4).setCellValue("Saldo");*/
  34.  
  35.            fila.getCell(0).setCellValue(movimientos.get(i).getFecha().toLocaleString());
  36.  
  37.            fila.getCell(1).setCellValue(movimientos.get(i).getDescripcion());
  38.            fila.getCell(2).setCellValue(movimientos.get(i).getSerie());
  39.            fila.getCell(3).setCellValue((double)movimientos.get(i).getMonto());
  40.            fila.getCell(4).setCellValue((double)movimientos.get(i).getSaldo());
  41.  
  42.        }
  43.  
  44.  
  45. /*
  46.         HSSFCellStyle cellStyle = wb.createCellStyle(); //estilo para la primera fila
  47.         HSSFCellStyle estilo = wb.createCellStyle(); // otro estilo para la segunda fila
  48.         HSSFCellStyle estilo2 = wb.createCellStyle();
  49.  
  50.  
  51.         cellStyle.setFillForegroundColor(HSSFColor.LIGHT_ORANGE.index);// color Naranjo
  52.         cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
  53.  
  54.         estilo.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index);//estilo para la segunda fila
  55.         estilo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
  56.  
  57.         estilo2.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
  58.         estilo2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);*/
  59.        System.out.println("El documento pesa : " + wb.getBytes().length);
  60.  
  61.        try {
  62.            FacesContext facesContext = FacesContext.getCurrentInstance();
  63.            HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
  64.            //  response.resetBuffer();
  65.  
  66.            response.setContentLength(wb.getBytes().length);
  67.            response.setContentType("application/vnd.ms-excel");
  68.  
  69.  
  70.  
  71.            //     System.out.println("RespuestA ? : " + response.getOutputStream().toString());
  72.            //      ServletOutputStream out = response.getOutputStream();
  73.  
  74.            ServletOutputStream out = response.getOutputStream();
  75.  
  76.            out.write(wb.getBytes());
  77.       //     out.flush();
  78.            out.close();
  79.            //   baosPDF.flush();
  80.            //  baosPDF.close();
  81.            facesContext.responseComplete();
  82.        } catch (Exception e) {
  83.            System.out.println("Error : " + e.getMessage());
  84.            e.printStackTrace();
  85.        }
  86.        // estilo2.setFont(HSSFFont.);
  87.  
  88.        // Este ciclo pintara todas las celdas de la fila 1
  89.  /*      for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
  90.         //header.getPhysicalNumberOfCells obtiene el numero de celdas de la fila
  91.         HSSFCell cell = header.getCell(i);
  92.        
  93.         cell.setCellStyle(cellStyle);//le asigna el estilo a cada celda de la primera fila
  94.         sheet.autoSizeColumn((short) i); // Deja las columnas en un tamaño que se vea todo bien.
  95.         System.out.println("Numero : " + i);//Cantidad de celdas rellenadas
  96.         }
  97.        
  98.        
  99.         // pruebas con las columnas
  100.         // Pintara toda la columna 3 de todas las filas.
  101.         for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
  102.        
  103.         HSSFRow fila = sheet.getRow(i);
  104.         HSSFCell cell = fila.getCell(2);
  105.         cell.setCellStyle(estilo2);
  106.        
  107.         }
  108.         /*Este ciclo pintara todas las celdas de la fila 2
  109.         for (int i = 0; i < fila.getPhysicalNumberOfCells(); i++) {
  110.         HSSFCell cell = fila.getCell(i);
  111.         cell.setCellStyle(estilo);
  112.         }*/
  113.  
  114.    }
  115.  
  116.  

Se agradece cualquier ayuda, sugerencia, gracias de antemano.
56  Foros Generales / Sugerencias y dudas sobre el Foro / Problemas de conexion con el foro? en: 23 Octubre 2011, 05:15 am
Que le pasa al foro, sale problemas con conectar a la base de datos reiteradas veces, espero que este todo ok, pero por curiosidad pregunto, saludos!.
57  Programación / Java / Java JSF exportar flash a pdf [SOLUCIONADO] en: 19 Octubre 2011, 15:36 pm
Estimados, estoy trabajando con amchart, unos graficos en flash y ademas estoy importando ese flash a pdf, si lo hago con un FileOutputStream funciona bien, pero si lo quiero ver en linea, no me lo genera, voy a publicar el metodo completo para que ustedes puedan ayudarme, de antemano muchas gracias.

Código
  1.  public void doPost() throws ServletException, IOException, DocumentException {
  2.  
  3.        System.out.println("Entre al metodo doPost");
  4.        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
  5.  
  6.        String heightStr = request.getParameter("height") == null ? "0" : request.getParameter("height");
  7.        String widthStr = request.getParameter("width") == null ? "0" : request.getParameter("width");
  8.        int height = 520;
  9.        int width = 300;
  10.        //int height = Integer.parseInt(heightStr.indexOf(".") == -1 ? heightStr : heightStr.substring(0, heightStr.indexOf(".")));
  11.        // int width = Integer.parseInt(widthStr.indexOf(".") == -1 ? widthStr : widthStr.substring(0, widthStr.indexOf(".")));
  12.        BufferedImage image = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB);
  13.        Graphics g = image.getGraphics();
  14.  
  15.        String current_row = "";
  16.        Image docImage = null;
  17.        try {
  18.            for (int i = 0; i < height; i++) {
  19.                current_row = request.getParameter("r" + i) == null ? "" : request.getParameter("r" + i);
  20.                System.out.println("Estoy dentro del ciclo y esta es la info : " + request.getParameter("r" + i) == null ? "" : request.getParameter("r" + i));
  21.                String current_col[] = current_row.split(",");
  22.                int current_width = 1;
  23.                for (int m = 0; m < current_col.length; m++) {
  24.                    String pixel[] = current_col[m].split(":");
  25.  
  26.                    if (pixel.length > 1) {
  27.                        g.setColor(this.charColor(pixel[0]));
  28.                        g.drawLine(current_width, i, current_width + Integer.parseInt(pixel[1]), i);
  29.                        current_width = current_width + Integer.parseInt(pixel[1]);
  30.                    } else if (pixel.length == 1) {
  31.                        g.setColor(this.charColor(pixel[0]));
  32.                        g.drawLine(current_width, i, current_width + 1, i);
  33.                        current_width++;
  34.                    }
  35.  
  36.  
  37.                }
  38.            }
  39.  
  40.            docImage = Image.getInstance(image, null);
  41.  
  42.        } catch (Exception e) {
  43.            e.printStackTrace();
  44.        }
  45.        g.create();
  46.  
  47.        Document doc = new Document();
  48.        ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
  49.        PdfWriter docWriter = null;
  50.        PdfWriter dos = null;
  51.  
  52.        try {
  53.            docWriter = PdfWriter.getInstance(doc, baosPDF);
  54.            dos = PdfWriter.getInstance(doc, new FileOutputStream("C:\\ejemplo.pdf"));
  55.  
  56.            doc.open();
  57.  
  58.            Table table = new Table(1, 1);
  59.            table.setWidth(100);
  60.            table.setTableFitsPage(true);
  61.            table.setAlignment(Table.ALIGN_LEFT);
  62.            table.setBorder(Table.NO_BORDER);
  63.  
  64.            Cell cell = new Cell();
  65.            cell.setBorder(Cell.NO_BORDER);
  66.            cell.setVerticalAlignment(Cell.ALIGN_TOP);
  67.            cell.add(docImage);
  68.  
  69.            table.addCell(cell);
  70.            doc.add(table);
  71.  
  72.            doc.close();
  73.  
  74.        } catch (DocumentException e) {
  75.            e.printStackTrace();
  76.        }
  77.  
  78.  
  79.  
  80.        try {
  81.            FacesContext facesContext = FacesContext.getCurrentInstance();
  82.            HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
  83.               //  response.resetBuffer();
  84.  
  85.            response.setContentType("application/pdf");
  86.  
  87.            response.setContentLength(baosPDF.size());
  88.            System.out.println("Tamaño BAOSPDF : " + baosPDF.size());
  89.            //     System.out.println("RespuestA ? : " + response.getOutputStream().toString());
  90.            //      ServletOutputStream out = response.getOutputStream();
  91.  
  92.            ServletOutputStream out = response.getOutputStream();
  93.            baosPDF.writeTo(out);
  94.            out.write(baosPDF.toByteArray());
  95.            out.flush();
  96.            out.close();
  97.            //   baosPDF.flush();
  98.            //  baosPDF.close();
  99.            facesContext.responseComplete();
  100.        } catch (Exception e) {
  101.            System.out.println("Error : " + e.getMessage());
  102.            e.printStackTrace();
  103.        }
  104.  
  105.  
  106.        System.out.println("Sali del metodo dopost");
  107.  
  108.    }
  109.  

El error que me sale es el siguiente "INFO: Error : PWC3990: getWriter() has already been called for this response" He buscado multiples opciones, alternativas, y ninguna me ha servido, por eso acudo a ustedes, espero que me puedan ayudar o darme ideas al respecto, gracias!


PD: Coloque el mime type a word para ver lo que escribe y solo escribe html y body xD , si necesitan mas datos me avisan

PD2: El error esta exactamente acá  ServletOutputStream out = response.getOutputStream();

Después de varios dias de intento, la solución era bastante ridicula y simple xD

en el xhtml que llama el método lo tenia asi :



Código
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3.      xmlns:h="http://java.sun.com/jsf/html"
  4.      xmlns:f="http://java.sun.com/jsf/core">
  5. <h:body>
  6. #{pdfMB.doPost()}
  7. </h:body>
  8. </html>
  9.  

Y la solución es así.

La cosa es que al generar la pagina llamaba automaticamente al evento y generaba una excepcion en el response, pero si hacia que yo generara un evento y de ahí lo llamará automaticamente, entonces si funcionaba bien.

Me di cuenta porque si colocaba un boton que llamara al metodo me pintaba en negro el pdf, y no me tomaba los datos, entonces debí automatizar eso,  y aqui la respuesta.

Código
  1. <?xml version='1.0' encoding='UTF-8' ?>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml"
  5.      xmlns:h="http://java.sun.com/jsf/html"
  6.      xmlns:f="http://java.sun.com/jsf/core">
  7.  
  8.  
  9.    <h:body>
  10.        <h:form>
  11.            <f:event listener="#{pdfMB.doPost()}" type="preRenderView" />
  12.       <!-- <h:commandButton action="{pdfMB.doPost()}" />-->
  13.        </h:form>
  14.    </h:body>
  15.  
  16.  
  17. </html>
  18.  
58  Sistemas Operativos / GNU/Linux / Denegar Acceso a nuestro servidor / PC en: 1 Septiembre 2011, 19:58 pm
Hace poco detecte intrusos en el servidor en el cual administro intentando tener acceso desde el 2007 (Este año empece administrarlo, pero los log hablan por si solo) , mediante ssh  y ftp a través de fuerza bruta, lo más interesante de todo es que provenian desde China, Israel, dos ataques que detecte esta ultima semana. La solución no puede ser mas simple: La posteo porque a cualquier le podría servir, disculpenme si ya estaba.

Mediante netstat -n vi al intruso en mi conexion:

Código
  1. tcp        0      0 ::ffff:192.168.0.4:22       ::ffff:121.14.118.4:46583   ESTABLISHED
  2.  

en /etc/ hay un fichero llamado hosts.deny

lo modifcamos desde la consola

nano /etc/hosts.deny

le colocamos
SERVICIO:IP //con esto denegamos a la ip acceder a el servicio que colocaremos, pero en mi caso era mas drastico, no quiero gente intrusa en mi servdiro asi que le aplico la denegacion de todos mis servicios a esa ip


ALL:ip
Quedaría algo asi el fichero.
Código
  1. #
  2. # hosts.deny    This file describes the names of the hosts which are
  3. #               *not* allowed to use the local INET services, as decided
  4. #               by the '/usr/sbin/tcpd' server.
  5. #
  6. # The portmap line is redundant, but it is left to remind you that
  7. # the new secure portmap uses hosts.deny and hosts.allow.  In particular
  8. # you should know that NFS uses portmap!
  9. ALL: 193.105.99.122
  10. ALL: 218.28.4.58
  11. ALL: 121.14.118.4
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
Ahora despues de los cambios miren como cambio el estado de la conexion
Código
  1. tcp        0      0 ::ffff:192.168.0.4:22       ::ffff:121.14.118.4:46583   TIME_WAIT  
  2.  

Hasta desaparecer de las conexiones intrusas.
59  Sistemas Operativos / GNU/Linux / Asignarle más recursos a un servicio, cómo? en: 1 Septiembre 2011, 15:11 pm
Estimados, esta es mi duda:

Tengo un servidor con redhat y lo administro via ssh, la cosa es la siguiente:

Quiero darle prioridad maxima a un servicio, ojalá que cuando se use el servicio que ocupe el 100 % de cpu  + toda la ram posible sin que deje la cagada obviamente, la cosa es que le aumente la prioridad a -15 lo maximo creo que es -19 o -20 no recuerdo, la cosa es que aun asi no me ocupa ni el 5 % de cpu cuando saco un fichero gigante en excel mediante sql, la cosa es que ocupe todos los recursos disponibles para cuando se use el mysql en una consulta de gran tamaño. La cosa es, como rayos hago eso, ya le di la prioridad alta al mysql y al httpd que puedo hacer para que me funcione bien .

aca un pantallazo:



PD: la aplicacion es en php.
60  Programación / PHP / Errores en php, donde se almacenan en: 1 Septiembre 2011, 03:26 am
Estimados esa es mi consulta, tengo un servidor con redhat sin interfaz grafica, tiene estos servicios instalados

apache
php 4
mysql

la cosa es que quiero saber donde se registran los log de errores en php por defecto en linux, gracias de antemano.
Páginas: 1 2 3 4 5 [6] 7 8 9
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines