从http客户端获取404

时间:2013-10-04 07:28:55

标签: java httpclient

这里我使用HTTP-CLIENT来调用servlet但是如果我只是点击“http://:8080 / RemediPRMS / WritePingData”这个链接它给了我响应代码200但是如果我从applet运行它它给了我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 个答案:

答案 0 :(得分:1)

您需要在网址中输入主机名

e.g。

http://myserver:8080/RemediPRMS/WritePingData

或者假设你是,一个仍然是沙箱的小程序不能

他们无法连接或检索来自任何第三方服务器(源自其服务器以外的任何服务器)的资源。

请参阅http://docs.oracle.com/javase/tutorial/deployment/applet/security.html