使用(tomcat + AXIS2)的Java Web服务,应用程序的根目录在哪里? [英] web service in Java using (tomcat + AXIS2), where is the root of the application?

查看:135
本文介绍了使用(tomcat + AXIS2)的Java Web服务,应用程序的根目录在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个将图像下载到本地Web服务器的功能. 当我像Java应用程序一样运行此功能时,它可以正常工作.但是,当我尝试使用AXIS2制作的Web服务运行此方法时( http://localhost:8080/axis2/services/adoroCinemaService2/downloadPhoto ),则AXIS2返回内部服务器错误.

I create a function that downloads a image to my local web server. When I run this function like a Java Application, it works fine. But when I try to run this method using the Web Service made by AXIS2 ( http://localhost:8080/axis2/services/adoroCinemaService2/downloadPhoto ), the AXIS2 returns Internal server error.

这很可能发生,因为我在代码中使用了根路径".那么,我需要做些什么来解决这个问题呢?服务的根源在哪里?如何设置此路径?

It happens probabily, because I use a "root path" in my code. So, what I need to do to solve this problem? Where is the root of my service? How can I setup this path?

    public void downloadPhoto() throws IOException{

    URL url = new URL("http://vamosla.mobi/img/bonde.png");
    String target = "vamosla.jpg";  

    HttpURLConnection c = (HttpURLConnection)url.openConnection();
    c.setRequestMethod("GET");
    c.setDoOutput(true);
    c.connect();

    FileOutputStream f = new FileOutputStream(new File(target));

     InputStream in = c.getInputStream();
        byte[] buffer = new byte[1024];
        int len1 = 0;
        while ( (len1 = in.read(buffer)) > 0 ) {
            f.write(buffer,0, len1);
        }

        f.close();
}

推荐答案

嗯,肯定有一些技巧可以弄清楚代码当前执行的位置并从那里设置相对路径,但是我认为这样做不会可靠为你.

Hm, there are certainly some tricks available to work out where the code currently executes and setup relative paths from there, but i don't think that will work reliably for you.

因此,我建议您通过系统属性或通过从类路径加载的某些配置文件来配置类似"asset.path"的内容.

Therefore, i suggest you configure something like an 'asset.path' either via system properties or via some configuration file you load from your classpath.

这篇关于使用(tomcat + AXIS2)的Java Web服务,应用程序的根目录在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆