如何在jsf页

时间:2016-01-28 12:06:33

标签: jsf servlets applet

我用java applet扫描图片之后需要在我的露天服务器上传,所以我认为我可以用http请求发送数据 但我不知道如何告诉我的jsf页面来处理这个请求  在这里我的网页:

<h:form id="docForm">
                        <h:outputText rendered="#{documentAjoutBean.showGedErrorMessage}"
                                value="#{msg.errorCodeGedConnexion}" styleClass="error"
                                style="margin-left: 3px; padding-bottom: 3px;" />
                            <rich:messages ajaxRendered="true" errorClass="msgError"
                                styleClass="error" />
                            <h:panelGrid columns="2">
                                <h:column>
                                    <h:outputText value="#{msg.DocumentRefCourrier}"
                                        styleClass="xteDetailLabel" />
                                </h:column>
                                <h:outputText
                                    value="#{documentAjoutBean.courrier.courrierReferenceCorrespondant}"
                                    styleClass="xteDetailLabel" />
                                <h:column>
                                    <h:outputText value="#{msg.DocumentRef}"
                                        styleClass="xteDetailLabel" />
                                    <rich:spacer width="10px" />
                                    <h:outputText value="*" styleClass="error" />
                                </h:column>
                                <h:inputText id="ref"
                                    value="#{documentAjoutBean.document.documentReference}"
                                    required="true"
                                    requiredMessage="* #{msg.ColonneDocRef} #{msg.champsobligatoire}" />

                                <h:column>
                                    <h:outputText value="#{msg.DocumentNom}"
                                        styleClass="xteDetailLabel" />
                                    <rich:spacer width="10px" />
                                    <h:outputText value="*" styleClass="error" />
                                </h:column>
                                <h:inputText id="nom"
                                    value="#{documentAjoutBean.document.documentNom}"
                                    required="true"
                                    requiredMessage="* #{msg.ColonneDocNom} #{msg.champsobligatoire}" />

                                <h:column>
                                    <h:outputText value="#{msg.DocumentObjet}"
                                        styleClass="xteDetailLabel" />
                                    <rich:spacer width="10px" />
                                    <h:outputText value="*" styleClass="error" />
                                </h:column>
                                <h:inputText id="obj"
                                    value="#{documentAjoutBean.document.documentObjet}"
                                    required="true"
                                    requiredMessage="* #{msg.ColonneDocObjet} #{msg.champsobligatoire}" />

                                <h:outputText value="#{msg.DocumentCommentaire}"
                                    styleClass="xteDetailLabel" />
                                <h:inputTextarea id="commentaire"
                                    value="#{documentAjoutBean.document.documentCommentaire}" />
                                <h:column />
                            </h:panelGrid>
                            <br />
                            <div>
                                <ui:include src="../framGraphique/upload.xhtml"></ui:include>
                            </div>
                            <br />
                            <rich:spacer height="10" />
                            <div align="center">
                                <a4j:commandButton value="#{msg.bouttonAjouter}" type="submit"
                                    action="#{documentAjoutBean.save}" status="ajaxStatus"
                                    disabled="#{documentAjoutBean.showGedErrorMessage}"
                                    oncomplete="if(#{documentAjoutBean.status}==true) 
                                    #{rich:component('msgPanal')}.show();"
                                    reRender="msgPanal,docForm"></a4j:commandButton>

                                <a4j:commandButton value="#{msg.bouttonAnnuler}"
                                    onclick="document.location.href='courrierConsulterDetails.jsf'" />
                            </div>
                            <rich:spacer height="10" />
                            <div align="left">
                                <h:outputText value="#{msg.infoChampObligatoir}" />
                            </div>
                        </h:form>

这是我的web.xml:

<servlet>
  <display-name>ScannerServlet</display-name>
  <servlet-name>scanner</servlet-name>
  <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
 </servlet>
 <servlet>
  <servlet-name>simple-form</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value/>
  </init-param>
 </servlet>
 <servlet-mapping>
  <servlet-name>scanner</servlet-name>
  <url-pattern>/scanner</url-pattern>
 </servlet-mapping>

这是我的servlet:

@Component("scanner")
   public class ScannerServlet implements HttpRequestHandler {

@Autowired
ScannerService scannerSevrice;

@PostConstruct
public void Initialize() {
    System.out
            .println("################################init Scanner Servlet##################################");
}

@Override
public void handleRequest(HttpServletRequest request,
        HttpServletResponse response) {
    System.out.println("ScannerServ-*-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    ByteArrayOutputStream byteArrayOutputStream = null;
    int len = 0;
    int size = 1024;

    byte[] data;
    DataInputStream dataInputStream = null;

    try {
        dataInputStream = new DataInputStream(request.getInputStream());
        byteArrayOutputStream = new ByteArrayOutputStream();
        data = new byte[1024];
        while ((len = dataInputStream.read(data, 0, 1024)) != -1) {
            System.out.println("  setData!!!");
            byteArrayOutputStream.write(data, 0, len);
            data = byteArrayOutputStream.toByteArray();

        }
            scannerSevrice.setData(ScannerUtils
                    .imageByteArrayToPdfByteArray(data));

        dataInputStream.close();

        System.out.println("received " + data.length + " bytes from "
                + request.getRemoteAddr());
        System.out.println("converted image to pdf with : "
                + scannerSevrice.getData().length + " bytes");
        DataOutputStream dataOutputStream = new DataOutputStream(
                response.getOutputStream());
        dataOutputStream.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

}

}

0 个答案:

没有答案