Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 未调用handleFileUpload_Jsf_File Upload_Primefaces - Fatal编程技术网

Jsf 未调用handleFileUpload

Jsf 未调用handleFileUpload,jsf,file-upload,primefaces,Jsf,File Upload,Primefaces,我的文件上传有一个奇怪的问题 handleFileUpload从未被调用,在xhtml文件中,它用黄色下划线,并表示Unknown属性 这是我的web.xml <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-

我的文件上传有一个奇怪的问题

handleFileUpload从未被调用,在xhtml文件中,它用黄色下划线,并表示Unknown属性

这是我的web.xml

<context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>
    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    </servlet>
这是我的uploadText.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:corejsf="http://corejsf.com"> 
    <h:outputStylesheet name="css/testcss.css" />
    <h:head>
        <title>Print to Uni</title>
        <meta http-equiv="content-type" content="text/html; charset=windows-1252" />
        <!-- <link rel="stylesheet" type="text/css" href="style.css" title="style" /> -->
    </h:head>
    <body>
        <div id="main">
            <div id="header">

                <div id="logo">
                    <div id="logo_text">
                        <h1><a href="/GUI/index.xhtml">Remote<span class="logo_colour">Printing</span></a></h1>
                        <h2>This is a web app that allows users to print to University</h2>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <div id="site_content">
        <div id="content">
            <h:body>
                <h:form enctype="multipart/form-data">
                    Upload a text file:
                    <h:form>
                        <!--<p:growl id="messages" showSummary="true" showDetail="true" /> -->
                        <br></br>
                        <br></br>

                        <p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
                                      mode="advanced" 
                                      update="messages"
                                      sizeLimit="100000000" 
                                      allowTypes="/(\.|\/)(gif|jpe?g|png|doc|docx|txt|pdf)$/"
                                      auto="true"/>
                        <p:growl id="messages" showDetail="true"/>
                    </h:form>
                    <br></br>
                    <br></br>
                    <p:commandButton value="Submit" action="/GUI/submittedText" icon ="ui-icon-arrowstop-1-n"/>
                    <div class="divider"/>
                    <p:commandButton  value="Homepage" action="#{userBean.buttonHome}" icon="ui-icon-home"/>   
                </h:form>
            </h:body>
        </div>
    </div>
</html>

打印到Uni
这是一个允许用户打印到大学的web应用程序
上载文本文件:








我的库中需要两个公共文件,这是什么原因造成的?我确实让它工作了,但没有备份更改,现在它不工作了

您的HTML正在运行。其中,您有多个
标记,并且嵌套
元素。JSF看起来像一个魔术师,但如果您强制它生成语法无效的HTML,那么它就不能为您做很多事情。当涉及到语法无效的HTML时,浏览器bahavior未指定。使用嵌套表单通常是导致浏览器没有向服务器提交预期数据,从而服务器没有收到任何结果的原因

您的HTML应该只有一个
标记(用JSF术语来说,就是只有一个
)。您的HTML也不应该有嵌套的
元素(在JSF术语中,您不应该相互嵌套
)。在浏览器中打开页面,右键单击并查看源代码。将其复制粘贴到重新链接的W3验证器中,并单独修复问题

除此之外,您的托管bean没有分配范围注释。它的行为类似于
@NoneScoped
,因此每次在EL中引用它时都会重新创建,从而导致在完全不同的实例中设置和调用模型属性和操作。至少将HTML设置为
@viewscope
。其中,您有多个
标记,并且嵌套
元素。JSF看起来像一个魔术师,但如果您强制它生成语法无效的HTML,那么它就不能为您做很多事情。当涉及到语法无效的HTML时,浏览器bahavior未指定。使用嵌套表单通常是导致浏览器没有向服务器提交预期数据,从而服务器没有收到任何结果的原因

您的HTML应该只有一个
标记(用JSF术语来说,就是只有一个
)。您的HTML也不应该有嵌套的
元素(在JSF术语中,您不应该相互嵌套
)。在浏览器中打开页面,右键单击并查看源代码。将其复制粘贴到重新链接的W3验证器中,并单独修复问题


除此之外,您的托管bean没有分配范围注释。它的行为类似于
@NoneScoped
,因此每次在EL中引用它时都会重新创建,从而导致在完全不同的实例中设置和调用模型属性和操作。至少让它成为
@ViewScoped

非常感谢您如此有用的解释非常感谢您如此有用的解释
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:corejsf="http://corejsf.com"> 
    <h:outputStylesheet name="css/testcss.css" />
    <h:head>
        <title>Print to Uni</title>
        <meta http-equiv="content-type" content="text/html; charset=windows-1252" />
        <!-- <link rel="stylesheet" type="text/css" href="style.css" title="style" /> -->
    </h:head>
    <body>
        <div id="main">
            <div id="header">

                <div id="logo">
                    <div id="logo_text">
                        <h1><a href="/GUI/index.xhtml">Remote<span class="logo_colour">Printing</span></a></h1>
                        <h2>This is a web app that allows users to print to University</h2>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <div id="site_content">
        <div id="content">
            <h:body>
                <h:form enctype="multipart/form-data">
                    Upload a text file:
                    <h:form>
                        <!--<p:growl id="messages" showSummary="true" showDetail="true" /> -->
                        <br></br>
                        <br></br>

                        <p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
                                      mode="advanced" 
                                      update="messages"
                                      sizeLimit="100000000" 
                                      allowTypes="/(\.|\/)(gif|jpe?g|png|doc|docx|txt|pdf)$/"
                                      auto="true"/>
                        <p:growl id="messages" showDetail="true"/>
                    </h:form>
                    <br></br>
                    <br></br>
                    <p:commandButton value="Submit" action="/GUI/submittedText" icon ="ui-icon-arrowstop-1-n"/>
                    <div class="divider"/>
                    <p:commandButton  value="Homepage" action="#{userBean.buttonHome}" icon="ui-icon-home"/>   
                </h:form>
            </h:body>
        </div>
    </div>
</html>