简体   繁体   English

如何从服务器上部署的Java Web服务访问本地文件?

[英]How can I access a local file from a Java webservice deployed on a server?

I have created a Java webservice that performs a specified function on a chosen file. 我创建了一个Java Web服务,它对所选文件执行指定的功能。 I will have to deploy the service to the server and will be calling the url to thr service from my Java code. 我将不得不将该服务部署到服务器,并将从我的Java代码中调用服务的URL。 Now, the file on which the function is to be performed has to be sent in post header as a parameter to the webservice. 现在,要在其上执行该功能的文件必须以post标头形式发送给Web服务。 How can I access this file path from the server? 如何从服务器访问此文件路径? If I simply send the path to that file (eg C:/folder/file.pdf) as a parameter to the webservice, will it work? 如果我只是将路径作为文件的参数发送到该文件(例如C:/folder/file.pdf),它将起作用吗? If not, how can that be achieved? 如果没有,那将如何实现?

I need to know the answer before the service is deployed. 在部署服务之前,我需要知道答案。

The webclient is as follows: Web客户端如下:

WebTarget webTarget = clientobj.target("http://localhost:8080/myWebApp/method1/Name1");
            MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
            formData.add("methodName", methodName);
            formData.add("pdfPath", "C:/folder/a.pdf"); //path to my pdf doc that needs to be sent to the server
            formData.add("textFile", "C:/folder/b.txt");
            Response response = webTarget.request().post(Entity.form(formData));
            String output = response.readEntity(String.class);

and the webservice is as follows: 和Web服务如下:

@POST
    @Produces(MediaType.TEXT_PLAIN)
    public String createBooking(@PathParam("methodName") String methodName, 
            @FormParam("pdfPath") String pdfPath, 
            @FormParam("textFile") String textFile))
{
PdfReader reader = new PdfReader(pdfPath);
}

There are two approach to do that. 有两种方法可以做到这一点。

1- If your machine and server are in same network and have shared resources then your server can directly access that file. 1-如果您的机器和服务器位于同一网络中并且具有共享资源,则您的服务器可以直接访问该文件。

2- This is most significant method. 2-这是最重要的方法。 You first need to upload that file to your server and then write that file on your server and do what you want with that file. 您首先需要将该文件上传到服务器,然后将该文件写入服务器,然后对该文件执行所需操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Java将文件从本地计算机上传到Web服务以进行ftp传输? - How can I upload a file from my local machine to a webservice for ftp transfer using java? 如何从已部署的Web应用程序访问本地文件系统上的文件? - how to access files on local file system from deployed web app? 如何从部署在其上的Java Web应用程序访问tomcat日志文件? - How can I access tomcat log files from Java web application deployed on it? 如何从使用Spring部署的JAX-WS Web服务WSDL更改自动生成的soap:地址 - How can I change the autogenerated soap:address from a JAX-WS webservice WSDL deployed with Spring 使用Java从已部署的服务器(即我的webApplication)从用户本地计算机访问文件 - Accessing files from users local machine from deployed server (i.e. my webApplication) in java 从BB仿真器访问部署在本地jboss服务器上的Web服务 - Access webservices deployed on a local jboss server from bb simulator 如何从本地主机访问本地文件 - How can access local file from localhost 如何将已部署的应用程序从应用程序服务器更改为Web服务器? - How can i change deployed application to webserver from application server? 我如何将图像对象从php发送到Java Web服务 - how can i send image object from php to Java webservice 如何访问已部署的战争文件? - How do I access deployed war file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM