0

Here I am using HTTP-CLIENT to call servlet but if I just click on "http://:8080/RemediPRMS/WritePingData" this link it gives me response code 200 but if I run it from applet it gives me 404.

    Deployment descriptor mapping is :
     <servlet>
        <servlet-name>WritePingData</servlet-name>
        <servlet-class>com.clientToServer.FileUploader.WritePingData</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>WritePingData</servlet-name>
        <url-pattern>/WritePingData</url-pattern>
      </servlet-mapping>

    try{
                System.out.println("folder.listFiles().length"+folder.listFiles().length);
                if(folder.listFiles().length > 0){
                    System.out.println("inside if file found[][][[[][][][][][][");
                    String remediEndpoint = "http://<endpoint>:8080/RemediPRMS/WritePingData";
                    FileInputStream fis = null;
                    System.out.println("above for loop");
                    File arr[] =folder.listFiles();//file array
                    System.out.println("array pass");

                        PostMethod post = null;
                        System.out.println("just above for loop");
                        for(int i=0;i<arr.length;i++){
                            try{
                                System.out.println("inside for loop");
                                File targetFile = new File(path+"\\"+arr[i].getName());
                                fis = new FileInputStream(targetFile);
                                post = new PostMethod(remediEndpoint);
                                post.setRequestEntity(new InputStreamRequestEntity(fis, targetFile.length()));
                                post.setRequestHeader("Content-type","text/plain; UTF-8"); 
                                HttpClient httpclient = new HttpClient();
                                httpclient.setConnectionTimeout(10000);
                                int status = httpclient.executeMethod(post);
                                fis.close();
                                //boolean deletestatus= targetFile.delete();
                                System.out.println("status from server : "+status);
                            }catch(Exception e){
                                LOGGER.info("Exception in file upload (http client): "+e);
                            }
                        }
                        post.releaseConnection();
                    }else{
                        LOGGER.info("THERE IS NO MORE FILE TO UPLOAD ");
                    }
                }catch(Exception e){
                    LOGGER.info("No directory inside LogData: "+e);
                }

1 Answer 1

1

You need a host name entered as part of your url

e.g.

http://myserver:8080/RemediPRMS/WritePingData

Or assuming that you are, an applet that is still sandboxed can not

They cannot connect to or retrieve resources from any third party server (any server other than the server it originated from).

see http://docs.oracle.com/javase/tutorial/deployment/applet/security.html

Sign up to request clarification or add additional context in comments.

1 Comment

Ya i use same myserver means i added ip address there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.