Results 1 to 2 of 2
  1. #1
    kinguzzo is offline Member
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Default [JAVA] Applet and Servlet comunication

    Hi
    I have a problem with this applet. When i do --> req.getParameter("nome") in servlet code, eclipse give me a warning
    WARN [Parameters] Parameters: Character decoding failed. Parameter skipped.
    this is the applet code
    tex is an array of file's names that i would transfer to servlet.
    Java Code:
    File file=new File(tex[i]);
            		 
           	   		 try
            
            		 {
            	
            
            			 FileInputStream in = new FileInputStream(file);
             
            			 byte[] buf=new byte[in.available()];
            
            			 int bytesread = 0;
            
            			 String nome = nomi[i];
    
            			 String toservlet = "h**p://localhost:8080/Tesi2/servletupload?n="+nome;
            			 System.out.println(toservlet);
            			 URL servleturl = new URL(toservlet);
            			 URLConnection servletconnection = servleturl.openConnection();
            			 servletconnection.setDoInput(true);
            			 servletconnection.setDoOutput(true);
            			 servletconnection.setUseCaches(false);
            			 servletconnection.setDefaultUseCaches(false);
            			 DataOutputStream out=new DataOutputStream(servletconnection.getOutputStream());
            			 
            			 
            			 while( (bytesread = in.read( buf )) > -1 ){
            				          
            				 out.write( buf, 0, bytesread );
             
            			 }
            
            			 out.flush();
            			 out.close();
            			 in.close();
            			 System.out.println("file inviato");
            
            			 BufferedInputStream inputFromClient = new BufferedInputStream(servletconnection.getInputStream());
    
            			 inputFromClient.close();
            		 }
            		 catch(Exception e1)
            		 {
            			 e1.printStackTrace();
            		 }
    this is servlet's code
    Java Code:
     try
            {
        	System.out.println("ENTRATO NELLA SERVLET");
           // String fileName = 
            String path = ServletGestioneCartelle.getRoot()+(File.separator)+req.getParameter("nome");
            System.out.println(path);
         
           
            File yourFile = new File(path);
            FileOutputStream toFile = new FileOutputStream( yourFile );
            DataInputStream fromClient = new DataInputStream( req.getInputStream() );
           
            byte[] buff = new byte[1024];
            int cnt = 0;
                while( (cnt = fromClient.read( buff )) > -1 ) {
                toFile.write( buff, 0, cnt );
            }
            toFile.flush();
            toFile.close();
            fromClient.close();
           
        }
        catch(Exception e)
            {
            e.printStackTrace();
        }
    The problem is in the querystring...

    Java Code:
    13:29:08,000 WARN  [Parameters] Parameters: Character decoding failed. Parameter skipped.
    java.io.CharConversionException: isHexDigit
    	at org.apache.tomcat.util.buf.UDecoder.convert(UDecoder.java:88)
    	at org.apache.tomcat.util.buf.UDecoder.convert(UDecoder.java:49)
    	at org.apache.tomcat.util.http.Parameters.urlDecode(Parameters.java:429)
    	at org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:412)
    	at org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:363)
    	at org.apache.catalina.connector.Request.parseParameters(Request.java:2562)
    	at org.apache.catalina.connector.Request.getParameter(Request.java:1060)
    	at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:355)
    	at common.servletupload.doPost(servletupload.java:37)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
    	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
    	at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
    	at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    	at java.lang.Thread.run(Unknown Source)
    Servlet recieves parameter "nome" and creates files too, but file's length is 0 byte.
    any suggestions?

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    wouldn't you need to send a proper HTTP headers from the applet? such as it is now it looks like it just starts sending the file binary data up to the servlet.

Similar Threads

  1. applet servlet communication
    By viswamadhavi in forum Java Applets
    Replies: 0
    Last Post: 04-06-2009, 01:12 PM
  2. Replies: 1
    Last Post: 12-02-2008, 12:23 AM
  3. Applet > servlet file transfer
    By milkman128 in forum Java Applets
    Replies: 1
    Last Post: 11-15-2008, 03:21 PM
  4. Replies: 1
    Last Post: 01-28-2008, 10:49 AM
  5. applet servlet communication
    By hardc0d3r in forum Java Applets
    Replies: 1
    Last Post: 07-12-2007, 06:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •