Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12
  1. #1

    [JAVA/JSP] uso jsp con bean e servlet

    Ragazzi ho una jsp un bean una servlet e un form.
    Devo prendere i dati dal form attraverso la servlet e incremntare un intero e passarlo alla jsp. Ho fatto tutto, la stringa la riesco a passare alla jsp ma l'intero no. Sapete come si fa? Aiutatemi.
    Ripeto solo con la stringa funziona.
    Grazie a tutti quelli che rispondono.

    Questo è il codice della jsp:
    Più sotto c'è l'errore che mi da.

    codice:
        
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
        <HTML><HEAD><TITLE>kgkhg</TITLE>
        <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
        <%@page contentType="text/html" import="java.util.*,beanProva.*" %>
    
        <BODY>
        <h1> incrementa </h1>
    
        <LI> CIAO
        <% BeanRisposta beanRisposta = (BeanRisposta) session.getAttribute("beanrisposta");
        String incre= beanRisposta.getOpzione();
        int numero= Integer.parseInt(beanRiposta.getParametro());
    
        %>
        <h1> Il risultato è : <%= numero %><%= incre %>to</h1>
    
    
        </BODY>
        </HTML>
    codice:
    type Exception report
    
    message
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception
    
    org.apache.jasper.JasperException: Unable to compile class for JSP
    
    An error occurred at line: 10 in the jsp file: /incrementa.jsp
    Generated servlet error:
    BeanRisposta cannot be resolved to a type
    
    An error occurred at line: 10 in the jsp file: /incrementa.jsp
    Generated servlet error:
    BeanRisposta cannot be resolved to a type
    
    An error occurred at line: 10 in the jsp file: /incrementa.jsp
    Generated servlet error:
    beanRiposta cannot be resolved
    
    
    	org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
    	org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
    	org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
    	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	Prova.gotoPage(Prova.java:13)
    	Prova.doGet(Prova.java:37)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs

  2. #2

    Re: [JAVA/JSP] uso jsp con bean e servlet

    Originariamente inviato da Aglieglie

    int numero= Integer.parseInt(beanRiposta.getParametro());


    An error occurred at line: 10 in the jsp file: /incrementa.jsp
    Generated servlet error:
    beanRiposta cannot be resolved
    Guarda non so se è questo...ma hai sbagliato a scrivere il nome del bean.

    beanRiposta,invece di beanRisposta

    Ciao

  3. #3
    Grazie per la risposta.

    Ho corretto ma l'errore è sempre lo stesso.

    Sai aiutarmi?

  4. #4
    Utente di HTML.it L'avatar di dannie
    Registrato dal
    Aug 2005
    Messaggi
    336
    Sembra che non riconosca la classe BeanRisposta... sta nel package beanProva? Hai controllato errori di battitura/path/ecc.?

  5. #5
    Mi posti i metodi del bean? Se dici che con la stringa funziona, deve esserci qualcosa che nn va nel bean..

  6. #6
    Scusatemi ho correto qualcosa e adesso lo trova il bean. Solo che mi da questo errore. Se per capire vi serve qualcosa ditemelo che posto.
    Grazie a tutti quelli che mi stanno aiutando.

    codice:
    ype Exception report
    
    message
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception
    
    org.apache.jasper.JasperException: Unable to compile class for JSP
    
    An error occurred at line: 10 in the jsp file: /incrementa.jsp
    Generated servlet error:
    The method parseInt(String, int) in the type Integer is not applicable for the arguments (int)
    
    
    	org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
    	org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
    	org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
    	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	Prova.gotoPage(Prova.java:13)
    	Prova.doGet(Prova.java:37)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.

  7. #7
    Utente di HTML.it L'avatar di dannie
    Registrato dal
    Aug 2005
    Messaggi
    336
    Integer.parseInt(String valore) riceve come parametro la stringa valore (che si suppone contenga un intero) e ne restituisce il corrispondente int: dal tuo errore sembra che tu stia passando a parseInt un int invece di una stringa...

  8. #8
    avevi proprio ragione. GRAZIE
    ciao

  9. #9
    Utente di HTML.it L'avatar di dannie
    Registrato dal
    Aug 2005
    Messaggi
    336


  10. #10
    Ragazzi scusatemi ancora.

    Vorrei fare la stessa cosa di prima però usando i bean diversamente. O meglio in entrambi i modi.
    Questo è quello che ho fatto:

    codice:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD><TITLE>Digitalphoto.it</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
    <%@page contentType="text/html" import="java.util.*,beanProva.*" %>
    
    <BODY>
    <h1> incrementa </h1>
    <LI> CIAO
    <% BeanRisposta beanRisposta = (BeanRisposta) session.getAttribute("beanrisposta"); 
    	String incre= beanRisposta.getOpzione();
    	int numero= beanRisposta.getParametro();
    
    %>
    <h1> Il risultato è : <%= numero %><%= incre %>to</h1>
    
    
    <jsp:useBean id="beann" class="BeanRisposta" scope="application" />
    <jsp:getProperty name="beann" property="opzione"  />
    
    </BODY>
    </HTML>
    usando
    codice:
    <jsp:useBean id="beann" class="BeanRisposta" scope="application" />
    <jsp:getProperty name="beann" property="opzione"  />
    mi ritorna un intero 0 e una stringa vuota. A me serve che mi ritorna l'intero incrementato nella servlet come devo fare?

    In questo modo mi funziona ma io lo voglio fare in entrambi i modi:
    codice:
    % BeanRisposta beanRisposta = (BeanRisposta) session.getAttribute("beanrisposta"); 
    	String incre= beanRisposta.getOpzione();
    	int numero= beanRisposta.getParametro();
    
    %>
    <h1> Il risultato è : <%= numero %><%= incre %>to</h1>
    Grazie ancora

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.