简体   繁体   English

从faces-config运行servlet

[英]Running servlet from faces-config

It will be hard to explain.. So, in a.jsp I have something like this: 很难解释。.因此,在a.jsp中,我有这样的内容:

<h:form enctype="multipart/form-data" >
                    <td><input type="text" name="imgName" value="" size="7"/></td>
                    <td><input type="text" name="imgDesc" value="" size="30"/></td>
                    <td>
                        <x:upload target="/upload/#{loginBean.user.login}/#{loginBean.user.filesUploaded}_image.jpg"/>
                    </td>
                    <td>                            
                        <h:commandButton value="Send" action="submit"/>
                    </td>
                    </h:form>

Now, pressing "Send" button will run filter, because (as I assume) that filter runs for every Faces Servlet (so for every jsp?). 现在,按“发送”按钮将运行过滤器,因为(正如我假设的那样)该过滤器针对每个Faces Servlet(因此针对每个jsp?)运行。 My web.xml file: 我的web.xml文件:

    <filter>
      <filter-name>Upload Filter</filter-name>
      <filter-class>DomainModels.Adds.UploadFilter</filter-class>
      <init-param>
         <param-name>sizeThreshold</param-name>
         <param-value>1024</param-value>
      </init-param>
   </filter>
   <filter-mapping>
      <filter-name>Upload Filter</filter-name>
      <servlet-name>Faces Servlet</servlet-name>
   </filter-mapping>

How can I force running servlet after filtering? 过滤后如何强制运行servlet? I've read somewhere that I have to write simple <servlet> and <servlet-mapping> . 我读过某个地方,我必须编写简单的<servlet><servlet-mapping> Ok, so I've changed "action" attribute to "TestServlet.do", added this: 好的,因此我将“ action”属性更改为“ TestServlet.do”,并添加了以下内容:

   <servlet>
       <servlet-name>TestServlet</servlet-name>
       <servlet-class>DomainModels.Adds.AddImage</servlet-class>
   </servlet>
   <servlet-mapping>
       <servlet-name>TestServlet</servlet-name>
       <url-pattern>/TestServlet.do</url-pattern>
   </servlet-mapping>

but still my TestServlet doesn't work.. I was trying to add into faces-config.xml this: 但是我的TestServlet仍然不起作用。。我试图将其添加到faces-config.xml中:

<navigation-rule>
    <from-view-id>/upload/a.jsp</from-view-id>
    <navigation-case>
      <from-outcome>submit</from-outcome>
      <to-view-id>/TestServlet.do</to-view-id>
    </navigation-case>
  </navigation-rule>

but it gives no result.. Any ideas? 但是没有结果。有什么想法吗?

Replace <h:form> by <form> so that you can utilize the action attribute. <h:form>替换为<form>以便您可以使用action属性。

Alternatively, don't use a servlet, but just use a managed bean action the JSF way. 或者,不使用servlet,而仅以JSF方式使用托管bean动作。 You only need to implement decode() of that homegrown x:upload component accordingly that it puts the uploaded file which is collected by the filter as a bean property. 您只需要相应地实现该本地x:upload组件的decode() ,即可将过滤器收集的上载文件作为bean属性放置。 Or if that's too much work, just reuse an existing JSF file upload component, like Tomahawk's t:inputFileUpload . 或者,如果工作量太大,只需重用现有的JSF文件上传组件,例如Tomahawk的t:inputFileUpload How to use it can be found in this article . 如何使用它可以在本文中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM