-----BEGIN PGP SIGNED MESSAGE-----



Hi everybody,
i dont know if somebody can help me! I didnt get sucess to solve this
problem.
i have a doubt about an error message which came from TomCat, as listed
below.There is a servlet, named StarServletnew and showed at end of this
email, which instances a Bean, named FormBean, which uses some parameters
that comes from a multipart/form-data form. This servlet receives
parameters, like text fields, and a file stream.I am using Oreilly's
package(Multipartrequest class) to get all parameters and file contents, as
you can see below. However, i always get succeed with the  file uploading
process, but i always get a failure when i try to get the parameters
contents! I am using TOMCAT 3.1 and NT4.0.


T O M  C A T   M E S S A G E  E R R O R

Error: 500
Location: /examples/servlet/StarServletnew
Internal Servlet Error:

java.lang.NoSuchMethodError: FormBean: method
(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lja
va/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/l
ang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/
Stri
        at StarServletnew.doPost(StarServletnew.java, Compiled Code)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java,
Compiled Code)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:597)
        at
org.apache.tomcat.servlets.InvokerServlet.service(InvokerServlet.java:257)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java,
Compiled Code)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java, Compiled Code)
        at
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java,
Compiled Code)
        at java.lang.Thread.run(Unknown Source)





M A I N   S E R V L E T


import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.*;

/**************
Problemas - 
- - sempre o cookie e diferente - rever o que aparece como valor do cookie
- - nao consegue receber getAttribute
**************/ 

public class StarServletnew extends HttpServlet {

        private boolean bcookie=false;
        private boolean bsessao=false;
        private FormBean Fb;
        private ErrorBean Eb;
        private String cookName = "cookstar";
        public static final int segundosanual = 60*60*24*365;
        
        private String nome;
        private String nomeart;
        private String sexo;
        private String profissao;
        private String registro;
        private String dia;
        private String mes;
        private String ano;
        private String email;
        private String end;
        private String compl;
        private String bairro;
        private String cidade;
        private String estado;          
        private String cursomoda;
        private String cursoteatro;
        private String cursomusica;
        private String cursomodelo; 
        private String escolaridade;
        private String linguas;
        private String esportes;
        private String calcado;
        private String danca;
        private String alturamts;
        private String alturacms;
        private String peso;  
        private String foto;
        private String olhos;

        //M�todo Final 
        public void destroy(){
                System.out.println("Final do StarServlet");
        }  
        // Controle do SERVLET     
        public void doPost ( HttpServletRequest req, 
                                                HttpServletResponse res) 
                                                throws IOException,
ServletException {

                
                // Cria nomes para match com nome dos parametros
                String p01 = "nome";
                String p02 = "nomeart";
                String p03 = "sexo";
                String p04 = "dia";
                String p05 = "mes";
                String p06 = "ano";
                String p07 = "profissao";
                String p08 = "registro";
                String p09 = "end";
                String p10 = "compl";
                String p11 = "bairro";
                String p12 = "cidade";
                String p13 = "estado";
                String p14 = "email";   
                String p15 = "cursomoda";
                String p16 = "cursoteatro";
                String p17 = "cursomusica";
                String p18 = "cursomodelo";
                String p19 = "esportes";
                String p20 = "danca";
                String p21 = "escolaridade";
                String p22 = "linguas";
                String p23 = "calcado";
                String p24 = "alturamts";
                String p25 = "alturacms";
                String p26 = "peso";
                String p27 = "olhos";
                String p28 = "foto";
                
          MultipartRequest multi = new MultipartRequest(req,"d:\\salva");

                // Obtem parametros dos formularios JSP, identifica o nome e
grava
                // nas variaveis da classe. 

                Enumeration pNames = multi.getParameterNames();
                
                while (pNames.hasMoreElements())  {
                        String parName = (String)pNames.nextElement();
                        String parValue = multi.getParameter(parName);
                        if (p01.equals(parName)) nome         = parValue;
                        if (p02.equals(parName)) nomeart      = parValue;
                        if (p03.equals(parName)) sexo         = parValue;
                        if (p04.equals(parName)) dia          = parValue;
                        if (p05.equals(parName)) mes          = parValue;
                        if (p06.equals(parName)) ano          = parValue;
                        if (p07.equals(parName)) profissao    = parValue;
                        if (p08.equals(parName)) registro     = parValue;
                        if (p09.equals(parName)) end          = parValue;
                        if (p10.equals(parName)) compl        = parValue;
                        if (p11.equals(parName)) bairro       = parValue;
                        if (p12.equals(parName)) cidade       = parValue;
                        if (p13.equals(parName)) estado       = parValue;
                        if (p14.equals(parName)) email        = parValue;
                        if (p15.equals(parName)) cursomoda    = parValue;
                        if (p16.equals(parName)) cursoteatro  = parValue;
                        if (p17.equals(parName)) cursomusica  = parValue;
                        if (p18.equals(parName)) cursomodelo  = parValue;
                        if (p19.equals(parName)) esportes     = parValue;
                        if (p20.equals(parName)) danca        = parValue;

                        if (p21.equals(parName)) escolaridade = parValue;
                        if (p22.equals(parName)) linguas      = parValue;
                        if (p23.equals(parName)) calcado      = parValue;
                        if (p24.equals(parName)) alturamts    = parValue;
                        if (p25.equals(parName)) alturacms    = parValue;
                        if (p26.equals(parName)) peso         = parValue;
                        if (p27.equals(parName)) olhos        = parValue;

                        System.out.println("StarServlet lendo de Form1
valor=" + parValue);
                        }

                Enumeration files = multi.getFileNames();
                while (files.hasMoreElements())
                {
                        String name = (String)files.nextElement();
                        String type = multi.getContentType(name);
                        File f = multi.getFile(name);
                //      foto = f.toString();
                }


                // Teste de obter parametros
                System.out.println("StarServlet lendo de Form1 nome=" +
nome);
        //      System.out.println("StarServlet lendo de Form2 outros=" +
outros);

                // Check Sessao  - se ok
                if (verifySessao(req, res)) {


                // Check Cookie de Web cookstar 
                        // Se nao tem - Receber parametros e gravar no
Banco)
                if (!verifyCookie(req, res)) {

                                // Instancia Bean e passa como parametros as
variaveis da classe
                                try 
                                {

                            Fb = new FormBean(  nome,
                                                            nomeart,
                                                            sexo,
                                                        dia,
                                                        mes,
                                                        ano,
                                                        profissao,
                                                        registro,
                                                end,
                                            compl,
                                                bairro,
                                            cidade,
                                            estado,
                                            email,
                                                cursomoda,
                                                    cursoteatro,
                                                cursomusica,
                                            cursomodelo,
                                            esportes,
                                            danca,
                                                escolaridade,
                                            linguas,
                                            calcado,
                                            alturamts,
                                            alturacms,
                                                peso,
                                            olhos ); 

                                // teste de Instancia do Bean
                        System.out.println("StarServlet lendo do FormBean
outros = " + Fb.getOutros());

                                // cria Cookie com vida longa
                        String endIP = req.getRemoteAddr();
                                String cookValor = (endIP + nome + email);
                                Cookie starcookie = new Cookie(cookName,
cookValor);
                        starcookie.setMaxAge(segundosanual);
                                res.addCookie(starcookie);           
        
                                /**            
                                RequestDispatcher dispatcher = 
                                req.setAttribute("candidato", fb);
        
getServletContext().getRequestDispatcher("/examples/jsp/serstar/starend.jsp"
);
                                dispatcher.forward(req, res);

                            // Dispatcher para jsp Final - cadastrado com
sucesso 
                                String url="/jsp/serstar/Starend.jsp";
        
getServletContext().getRequestDispatcher(url).forward(req,res);
                                // res.sendRedirect(url);                
                                */
                                
                                // Nao funciona no Jakarta
                                // sc.setAttribute("candidato", Fb);
                        // System.out.println("setAttribute OK");
                                // RequestDispatcher rd = 
                                //
getServletContext().getRequestDispatcher("/jsp/serstar/Starend.jsp");
                                // rd.forward(req, res);

                                // Instancia Bean e armazena Objeto FB no
scopo para ser usado
                                // por outro servlet atraves de
(getAttribute)
                        System.out.println("Sessao e cookie Ok");
                                req.setAttribute("candidato", Fb);
                                RequestDispatcher rd = 
        
getServletContext().getRequestDispatcher("/jsp/serstar/Starend.jsp");
                                rd.forward(req, res);


                                /**
                                ServletContext sc = getServletContext();
                                int calledCount = 0;
                                if (sc.getAttribute("calledCount") != null)
{
                                Integer tempCount =
(Integer)sc.getAttribute("calledCount");
                                calledCount = tempCount.intValue();
                                }
                                out.println("ServletContext, server info: "
+ sc.getServerInfo() +
                                "<BR>");
                                out.println("SerlvetContext, real path: " +
sc.getRealPath("") + "<BR>");
                                out.println("The attribute 'calledCount'
value we retrieved: " +
                                calledCount + "<BR>");
                                calledCount++;
                                sc.setAttribute("calledCount", new
Integer(calledCount));
                                out.println("We set the ServletContext
attribute 'calledCount' to: " +
                                sc.getAttribute("calledCount"));
                                */

                                } catch (Exception e) {
                                System.out.println("Erro ao Instanciar bean
Formbean" + e);
                                e.printStackTrace();
                            }


               
                } else {

                        // Ja tem Cookie de Web cookstar - ja se cadastrou
anteriormente
                                // Dispatcher para jsp Final com mensagem de
< ja cadastrado >
                        System.out.println("Sessao e cookie No");
                                // ServletContext sc = getServletContext();
                                // sc.setAttribute("candidato", Fb);
                                req.setAttribute("candidato", Fb);
                                RequestDispatcher rd = 
        
getServletContext().getRequestDispatcher("/jsp/serstar/Starexist.jsp");
                                rd.forward(req, res);

                }        

                } else {

                        // Sessao invalida , dispatcher para errorpage.jsp
                System.out.println("Sessao No");
                        Eb = new ErrorBean();
                        Eb.setCoderror("ErrorS030");
                        RequestDispatcher rd = 
        
getServletContext().getRequestDispatcher("/jsp/serstar/Errorpage.jsp");
                        rd.forward(req, res);

                
                }
                
        }
        // Metodo Inicial 
        public void init(ServletConfig starserv) throws ServletException{
                super.init(starserv);
                System.out.println("Inicio do StarServlet");
        }  
        // Metodo que testa se ja tem Cookie de Web cookstar
        protected boolean verifyCookie( HttpServletRequest req,
        
HttpServletResponse res) {
                
                String endIP = req.getRemoteAddr();
                String cookValor = (endIP + nome + email);
            Cookie[] cookies = req.getCookies();
            for (int i=0; i < cookies.length; i++) {
                        Cookie cookie = cookies[i];
                if (cookName.equals(cookie.getName()) && 
                                cookValor.equals(cookie.getValue())) {
                                System.out.println("ok o cookie nome e : " +
cookie.getName() + " i=" + i);
                                System.out.println("ok o cookie valor e : "
+ cookie.getValue() + "i=" + i);
                    bcookie=true;
                        } else {
                                System.out.println("No o cookie nome e : " +
cookie.getName() + " i=" + i);
                                System.out.println("No o cookie valor e : "
+ cookie.getValue() + " i=" + i);
                        }
            }
                return bcookie;
        }
        // Metodo que testa se a sessao e v�lida
        protected boolean verifySessao( HttpServletRequest req,
        
HttpServletResponse res) {
                
                HttpSession session = req.getSession(true);
                Enumeration vNames = session.getAttributeNames();
                while (vNames.hasMoreElements())  {
                        String name = (String)vNames.nextElement();
                        String value =
session.getAttribute(name).toString();
                        if ( name == "serstar" &&
value.equals(req.getRemoteAddr())) {
                                System.out.println("Ok o nome  da sessao: "
+ name );
                                System.out.println("Ok o valor da sessao: "
+ value );
                                bsessao=true; 
                        } else {
                                System.out.println("No o nome  da sessao: "
+ name );
                                System.out.println("No o valor da sessao: "
+ value );
                        }                    
                }
                return bsessao;
        }
}


Jos� Euclides J�nior
__________________________________
E-mail: [EMAIL PROTECTED]
            [EMAIL PROTECTED] 
            [EMAIL PROTECTED]
http://euclides.8m.com


-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.1

iQCVAwUBOkzDUN0YhuJ3BUxtAQHh9AP9FEFFDQ/XsgyQdaga6IrU9bNO6J2etd5N
HDAOvFzoODgQkd4r4LXMmDJet/IfG9FI9YfqZoaF743MEiVs6CXPQI32zHzZmwdA
ehelgBwPU/CfZhS+umxxULvP3TLBvPAhgxZ8oXbKFPa1ni8wLZFxbYLNy1d6h6D5
/+qIpZTqPvE=
=zhPR
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to