如何使用java程序在tomcat webserver中创建文件夹? [英] how to create a folder in tomcat webserver using java program?

查看:201
本文介绍了如何使用java程序在tomcat webserver中创建文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在java中的webserver(tomcat 7.0)中创建一个文件夹。

i want to know how to create a folder in webserver(tomcat 7.0) in java.

iam最近启动了一个项目。在那个项目中我需要上传文件从客户端机器进入服务器。在这个服务器中每个客户端都有自己的文件夹并将文件上传到它们中。

iam recently start one project.In that project i need to upload files into server from the client machine.In this each client has his own folder in server and upload the files into them.

在每个用户文件夹中我们有两个以上的jsp files.when用户请求服务器通过URL显示其内容(例如:ipaddress:portnumber / userid / index.jsp),使用我想要显示其上传数据的文件。

And in each user folder we have more than two jsp files.when user request the server to show their content by an url (eg:ipaddress:portnumber/userid/index.jsp) using that files i want to show his uploaded data.

是否有可能。?

请指导我解决这个问题。
谢谢。

please,guide me to solve this problem. thanks.

推荐答案

关于具体问题,就像在普通Java应用程序中一样。

As to your concrete question, just the same way as in a normal Java application.

File root = new File("/path/to/all/uploads");
File newfolder = new File(root, "/userid");
newfolder.mkdir();
// ...

关于所有文件夹上的复制JSP文件的想法,不要那样做。只需要一个映射到例如 / files / * 的servlet,然后读取特定于当前登录用户的文件夹,最后转发到JSP以显示结果。或者,如果你的目的是让每个人公开上传,以便每个用户都可以看到彼此的上传,那么在请求URL中提供所需的用户ID作为参数或pathinfo,如此 http:// localhost :8080 / context / files / userid

As to your idea with those copypasted JSP files over all folders, don't do that. Just have a single servlet which is mapped on for example /files/* and reads the folder specific to the currently logged-in user and finally forwards to the JSP to present the results. Or if your intent is really to make the uploads public to everyone so that each user can see each other's uploads, then supply the desired user ID as parameter or pathinfo in the request URL like so http://localhost:8080/context/files/userid.

请注意,您不应将文件存储在展开的WAR文件夹中,否则它们将每次重新部署webapp时都会迷路。将它们存储在Tomcat的 / webapps 文件夹之外的固定路径上。

Please note that you shouldn't store the files in the expanded WAR folder, or they will get lost everytime you redeploy the webapp. Store them on a fixed path outside Tomcat's /webapps folder.

这篇关于如何使用java程序在tomcat webserver中创建文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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