Tomcat 7未从/ home目录加载图像

问题描述 投票:-1回答:1

我很难让图像显示在Tomcat中运行的JSP Web应用程序上。从添加MIME映射到更改context.xml文件以引用Webapp外部目录,我都尝试了所有方法。我还更改了目录所有权权限,但仍然没有得到预期的结果。文件路径值存储在数据库中。

此路径有效:/opt/tomcat/Harvester/Results/REQUESTID/REQUESTID_Image.FITS

此路径不是:/home/tomcat/harvester/results/REQUESTID/REQUESTID_Image.FITS

我已经确认文件存在,并且我不知道还需要配置什么才能显示第二个位置中引用的图像。

环境:

  • Cent OS 7
  • Apache Tomcat 7
  • java版本“ 1.8.0_191” Java(TM)SE运行时环境(内部版本1.8.0_191-b12)Java HotSpot(TM)64位服务器VM(内部版本25.191-b12,混合模式)
  • primefaces 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>

Requests.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
    }

RequestResult.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;
    }

使用“ journalctl -xe -u tomcat的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">
java linux primefaces server tomcat7
1个回答
1
投票

我在使用tomcat托管的其他应用程序时发现了问题。我对系统执行更新后,必须已启用SELinux。

SELinux是Linux内核模块,它提供了一个框架,用于为系统上的许多资源配置强制性访问控制。

我禁用了SELINUX,然后重新引导了我的虚拟机(关闭了虚拟机,重新启动了VMware,打开了虚拟机)。

键入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
© www.soinside.com 2019 - 2024. All rights reserved.