Java Jboss图像上传和http访问以显示图像
我通过使用以下代码获取绝对路径,将图像上传到jboss服务器Java Jboss图像上传和http访问以显示图像,java,jboss,image-uploading,Java,Jboss,Image Uploading,我通过使用以下代码获取绝对路径,将图像上传到jboss服务器 getServletContext().getRealPath(""); 上传的图像被移动到绝对路径,我可以使用 我的问题是,映像正在上载到jboss服务器的tmp目录,因此在下一次部署中,我将丢失上载的映像。 我尝试将图像上传到不同的路径以使其正常工作 \jboss-5.0.1.GA\server\default\deploy 这里还有\jboss-5.0.1.GA\server\default\work\jboss.web\lo
getServletContext().getRealPath("");
上传的图像被移动到绝对路径,我可以使用
我的问题是,映像正在上载到jboss服务器的tmp目录,因此在下一次部署中,我将丢失上载的映像。
我尝试将图像上传到不同的路径以使其正常工作
\jboss-5.0.1.GA\server\default\deploy
这里还有\jboss-5.0.1.GA\server\default\work\jboss.web\localhost
但是失败了,我无法使用
请帮我解决这个问题。您可以添加新上下文以指定访问外部文件夹的路径 Jboss 4及更早版本的步骤:
/YOURINSTANCE\u JBOSS/deploy/JBOSS web.deployer/server.xml
上下文
例如:
<Host name=”localhost” ...>
<Context path=”/myfolder” docBase=”/home/username/my_images” reloadable=”true”></Context>
public class MyResources extends FileDirContext {
}
Jboss 5的步骤:
WEB-INF
文件夹中创建一个名为context.xml
的新文件,其中包含以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<Context allowLinking="true" cookies="true" crossContext="true" override="true">
<Resources allowLinking="true" className="YOUR_PACKAGE.MyResources" homeDir="/home/username/my_images" />
</Context>
<?xml version="1.0" encoding="UTF-8"?>
<Context allowLinking="true" cookies="true" crossContext="true" override="true">
<Resources allowLinking="true" homeDir="/home/username/my_images" />
</Context>
request.getServletContext().getResourceAsStream(uri);
Jboss 5及更早版本的步骤:
context.xml
的新文件,其中包含以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<Context allowLinking="true" cookies="true" crossContext="true" override="true">
<Resources allowLinking="true" className="YOUR_PACKAGE.MyResources" homeDir="/home/username/my_images" />
</Context>
<?xml version="1.0" encoding="UTF-8"?>
<Context allowLinking="true" cookies="true" crossContext="true" override="true">
<Resources allowLinking="true" homeDir="/home/username/my_images" />
</Context>
Linux:
YourDeployedProject.war# ln -s /home/username/my_images myfolder
http://yourserver:yourport/myfolder/filename
http://localhost:8080/DeployedProject/myfolder/filename
Jboss 7的步骤:
JBoss 7不允许使用以前JBoss版本中的任何方法,因此最简单的解决方案是实现一个Servlet来访问下一个版本中的文件。非常感谢您的回答。我无法定义jboss-web.deployer文件夹。我在这个位置有另一个jboss-5.0.1.GA\server\default\deploy\jbossweb.sar,对吗?可能就是那个。我已经在我们的服务器JBoss4.2.2AS中完成了这个配置(我想在JBoss5中不会有太大的不同)。检查文件
server.xml
是否在您评论的文件夹中。如果我在server.xml中添加代码,服务器将不会启动。还有另一个名为context.xml的文件。如果我在这里添加,服务器中的应用程序都没有运行。@Jeyasithar在JBoss论坛中查看时发现:从版本5开始,它似乎只在外部文件夹位于JBoss\u HOME/server/default/deploy
中时才起作用。听到这个消息很高兴。谢谢你的回答。我现在试过了。但服务器尚未启动。可能是我用错了。能否请您相应地编辑答案,以便我可以实现相同的功能。再次感谢。