java - Tomcat 7 未从 /home 目录加载图像
问题描述
我在让图像显示在 Tomcat 中运行的 JSP Web 应用程序上时遇到了困难。我已经尝试了从添加 MIME 映射到更改 context.xml 文件以引用 webapp 之外的目录的所有方法。我还更改了目录所有权权限,但仍然没有得到预期的结果。文件路径值存储在数据库中。
此路径有效:/opt/tomcat/Harvester/Results/REQUESTID/REQUESTID_Image.FITS
此路径没有:/home/tomcat/harvester/results/REQUESTID/REQUESTID_Image.FITS
我已经确认文件存在,但我不知道还需要配置什么来显示第二个位置引用的图像。
环境:
- 美分操作系统 7
- 阿帕奇雄猫 7
- java 版本 "1.8.0_191" Java(TM) SE Runtime Environment (build 1.8.0_191-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, 混合模式)
- 素面5.3
Requests.xhtml 数据表有问题:
<p:dataTable id="RequestResults" var="RequestResult" value="#{Requests.allrequestresults}" selection="#{Requests.selectedrequestresults}" rowKey="#{RequestResult.id}" sortMode="multiple"
rows="10" paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,20,50,100"
resizableColumns="true" liveResize="true"
draggableColumns="true"
style="margin-bottom:20px; table-layout:auto;"
>
<f:facet name="header">
Results
</f:facet>
<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
<p:column headerText="Result ID" sortBy="#{RequestResult.id}" style="width: 200px">
<h:outputText value="#{RequestResult.id}" />
</p:column>
<p:column headerText="Request ID" sortBy="#{RequestResult.requestid}" style="width: 200px">
<h:outputText value="#{RequestResult.requestid}" />
</p:column>
<p:column headerText="File Name" sortBy="#{RequestResult.filename}" style="width: 200px">
<h:outputText value="#{RequestResult.filename}" />
</p:column>
<p:column headerText="Image" style="width: 100%">
<h:graphicImage id="image" name="results/#{RequestResult.imagename}" width="300" height="300"/>
<p:resizable for="image" animate="true" ghost="true"/>
</p:column>
</p:dataTable>
请求.java
public void LoadRequestResults(){
MySqlDB mysqldb = new MySqlDB(); //Open and close of the connection and it's contents must be handled
ResultSet resultsRS = null;
allrequestresults = new ArrayList();
String RequestReviewList = "";
for(Request r : selectedrequests)
{
if(RequestReviewList.matches("")) RequestReviewList = "'" + r.getId() + "'";
else RequestReviewList += ",'" + r.getId() + "'";
}
try{
String query = String.format("Select id, requestid, filename from RESULTS where requestid in (%s) order by requestid",
RequestReviewList);
resultsRS = mysqldb.ExecuteDataTable(query);
while (resultsRS.next()) {
allrequestresults.add(new RequestResult(resultsRS.getInt("id"),
resultsRS.getInt("requestid"),
resultsRS.getString("filename"),
RequestResult.convertFITSToPNGString(new File(resultsRS.getString("filename")), config.TempDir)
));
}
}catch(IOException | SQLException e){
downloadmsg = "Failed to load.: " + e.toString();
}
finally{
try{
mysqldb.close((Connection)((Statement)resultsRS.getStatement()).getConnection(),(Statement)resultsRS.getStatement(),resultsRS);
}
catch(Exception e) {
}
}
try{Thread.sleep(2000);}catch(Exception e){} //Wait for the files to be recognized by the web site
}
请求结果.java
public static String convertFITSToPNGString(File file, String tempfiledir){
String ReturnFileName = null;
try {
String TempFileName = file.getName().substring(0, file.getName().lastIndexOf(".")) + ".jpeg";
String TempFile = tempfiledir + TempFileName;
File f = new File(TempFile);
if(!f.exists())
{
Opener op = new Opener();
ImagePlus Imp = op.openImage(file.getPath());
FileSaver fileSaver = new FileSaver(Imp);
fileSaver.saveAsJpeg(TempFile);
}
ReturnFileName = TempFileName;
}catch(Exception e)
{
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, e.toString(), null));
//errorMSG = e.toString();
}
return ReturnFileName;
}
Tomcat日志使用“journalctl -xe -u tomcat”
Dec 31 22:30:51 server[4153]: Unsupported format or not found
Dec 31 22:30:51 server[4153]: Unsupported format or not found
Dec 31 22:30:51 server[4153]: Dec 31, 2019 10:30:51 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:51 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:51 server[4153]: Dec 31, 2019 10:30:51 PM com.sun.faces.application.resource.WebappResourceHelper findResource
Dec 31 22:30:51 server[4153]: WARNING: jsf.application.resource.unable_to_determine_resource_version.
Dec 31 22:30:51 server[4153]: Dec 31, 2019 10:30:51 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:51 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.application.resource.WebappResourceHelper findResource
Dec 31 22:30:53 server[4153]: WARNING: jsf.application.resource.unable_to_determine_resource_version.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.application.resource.WebappResourceHelper findResource
Dec 31 22:30:53 server[4153]: WARNING: jsf.application.resource.unable_to_determine_resource_version.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.application.resource.WebappResourceHelper findResource
Dec 31 22:30:53 server[4153]: WARNING: jsf.application.resource.unable_to_determine_resource_version.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
使用 Google Chrome 上的“检查”工具显示图像 URL 不完整:
<img id="form:RequestResults:0:image" src="/Website/javax.faces.resource/results/.xhtml" alt="" height="300" width="300">
解决方案
我在处理由tomcat托管的不同应用程序时发现了这个问题。在我对系统执行更新后,SELinux 必须已启用。
SELinux 是一个 Linux 内核模块,它提供了一个框架,用于为系统上的许多资源配置强制访问控制。
我禁用了 SELINUX,然后重新启动了我的虚拟机(关闭 VM,重新启动 VMware,启动 VM)。
键入nano /etc/sysconfig/selinux
并编辑要读取的文件:
#This file controls the state of SELinux on the system.
#SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced
# permissive - SELinux prints warnings instead of enforcing
# disabled - No SELinux policy is loaded
SELINUX = disabled
#SELINUXTYPE = can take one of these two values:
# targeted - Targeted processes are protected
# mls - Multi Level Security protection
SELINUXTYPE=targeted
我发现的另一个解决方案不是禁用 SELINUX,而是将 tomcat_t 守护进程的域(安全上下文)设置为许可模式。在许可模式下,不会强制执行该策略,但会在该策略通常拒绝的访问上生成日志。
类型semanage permissive -a tomcat_t
推荐阅读
- java - 短信通知默认声音的uri
- react-native - Android:react-native-image-picker manifest.xml 文件路径无效
- file - 如何为应用程序工作会话设置一次文件中的常量
- regex - 通过正则表达式识别句子中的单词
- c++ - 三元运算符为什么以及何时返回左值?
- python - 使用python计算肽单同位素
- c# - 尝试不每秒创建新文件,但如果文件限制超过则使用 log4net 创建新文件
- windows - 使用不带方括号的 dir /D 命令作为输出
- haskell - Haskell 中使用 List Monad 的下推自动机
- java - 如何分配多维输出缓冲区来提供 Android Tflite 的interpreter.run()?