0

我正在使用 Eclipse 使用 JSF、Hibernate 和 Tomcat 服务器。我在一个名为“ListeAutoTPEs.jsp”的jsp页面中,当提交表单时,会调用一个方法(它从jrxml文件创建一个PDF)但无法访问我提到的页面“test2.htm”在“成功”的导航案例中的 tha faces-config

我的 faces-config.xml 页面:

<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces 
 Config   1.0//EN"
                              "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
<faces-config>
 <managed-bean>
  <managed-bean-name>login</managed-bean-name>
  <managed-bean-class>com.axentis.jsf.LoginBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>
 <managed-bean>
  <managed-bean-name>traitement</managed-bean-name>
  <managed-bean-class>com.axentis.jsf.TraitementBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
   <property-name>executed</property-name>
   <property-class>java.lang.Boolean</property-class>
   <value>false</value>
  </managed-property>
 </managed-bean>
 <managed-bean>
  <managed-bean-name>autorisation</managed-bean-name>
  <managed-bean-class>com.axentis.jsf.AutoBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
   <property-name>ack</property-name>
   <property-class>java.lang.String</property-class>
   <value>ns</value>
  </managed-property>
 </managed-bean>
 <managed-bean>
  <managed-bean-name>match</managed-bean-name>
  <managed-bean-class>com.axentis.jsf.MatchBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
   <property-name>transac</property-name>
   <property-class>java.lang.String</property-class>
   <value>1</value>
  </managed-property>
 </managed-bean>
 <managed-bean>
  <managed-bean-name>trans</managed-bean-name>
  <managed-bean-class>com.axentis.jsf.TransacTelecolBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>
 <navigation-rule>
  <from-view-id>/login.jsp</from-view-id>
  <navigation-case>
   <from-outcome>ConSuccess</from-outcome>
   <to-view-id>/Accueil.jsp</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-outcome>Erreur</from-outcome>
   <to-view-id>/login.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>
 <navigation-rule>
  <from-view-id>/listeDeTousLesCom.jsp</from-view-id>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/listeDeTousLesCom.jsp</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-outcome>erreur</from-outcome>
   <to-view-id>/error.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>
 <navigation-rule>
  <from-view-id>/jsp/ListeAutoTPEs.jsp</from-view-id>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/test2.htm</to-view-id>
   <redirect/>
  </navigation-case>

  <navigation-case>
   <from-outcome>erreur</from-outcome>
   <to-view-id>/error.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>
 <navigation-rule>
  <from-view-id>/Matching.jsp</from-view-id>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/Matching.jsp</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-outcome>erreur</from-outcome>
   <to-view-id>/error.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>
 <navigation-rule>
  <from-view-id>/listeTransacTelecol.jsp</from-view-id>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/listeTransacTelecol.jsp</to-view-id>
  </navigation-case>
  <navigation-case>
   <from-outcome>erreur</from-outcome>
   <to-view-id>/error.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>
</faces-config>

我的托管豆:

public String toutLesAuto(){
String url = "jdbc:oracle:thin:@10.5.3.136:1521:orcl";
String login = "mawarid";
String password = "mawarid";
Connection connection = null;  
 try {
 // - Connexion à la base
 System.out.println("je suis dans le bean de traitement");
Driver monDriver = new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(monDriver);
connection = DriverManager.getConnection(url, login, password);
System.out.println("connection réussie");

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
ServletContext servletContext = (ServletContext) externalContext.getContext();
String absoluteDiskPath = servletContext.getRealPath("/");

// récupération des données saisies par le client

AutoBean auto = (AutoBean) FacesContext.getCurrentInstance().getExternalContext().
getSessionMap().get("autorisation");
if (auto!=null)
System.out.println("les donnée saisi par le clients sont : n° de la carte
"+auto.getNumCarte()+"  son code réponse  "+auto.getCodeRep()+" et la date saisie est
 : "+auto.getDate()+" le uméro d'autorisation est : "+auto.getNumAuto());
else 
System.out.println("le bean AutoBean n'a pas été instancié"); 

// - Chargement et compilation du rapport

JasperDesign jasperDesign = JRXmlLoader.load(absoluteDiskPath+"\\rapports  
\\ListeAuto.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

// - Paramètres à envoyer au rapport

String date="%";
String numCarte="%";
String numTpe="%";
String codeRep="%";
String numCommerçant="%";
String numAuto="%";
String mntDem="%";
String ack="%";
if(auto.getDate()!="")
date =auto.getDate();
if (auto.getNumCarte()!="")
numCarte=auto.getNumCarte();
if (auto.getCodeRep()!="")
codeRep=auto.getCodeRep();
if (auto.getNumAuto()!="");
numAuto=auto.getNumAuto();
if (auto.getNumCom()!="")
numCommerçant=auto.getNumCom();
if (auto.getNumTpe()!="")
numTpe=auto.getNumTpe();
if (auto.getAck()!=null)
ack=auto.getAck();

Map parameters = new HashMap();
parameters.put("date",date);
parameters.put("numCarte",numCarte);
parameters.put("numTpe",numTpe);
parameters.put("codeRep",codeRep);
parameters.put("numCommercant",numCommerçant);
parameters.put("numAuto",numAuto);
parameters.put("mntDem",mntDem);


// - Execution du rapport

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, 
 parameters,connection);
System.out.println("execution du rapport réussie");
// - Création du rapport au format PDF



JasperExportManager.exportReportToPdfFile(jasperPrint,absoluteDiskPath+"\\rapports
\\ListeAuto.pdf");
System.out.println("impression réussie");


if (auto!=null)
System.out.println("les donnée saisi par le clients sont : n° de la carte
 '"+numCarte+"'  " +"son code réponse  '"+codeRep+"' et la date saisie est  
  :'"+date+"' le uméro d'autorisation est : '"+numAuto+"l'accusé est : "+ack);



// popup to download the file


 response.reset(); 
 response.setContentType("application/xml"); 
 response.setHeader("Content-disposition", "attachment; filename=\"liste des    
 autorisations.pdf\"");

 byte[] buf = new byte[1024];
 try{

 System.out.println("le chemain "+absoluteDiskPath);
 String realPath =absoluteDiskPath+"\\rapports\\ListeAuto.pdf";
 File file = new File(realPath);
 long length = file.length();
  BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
 ServletOutputStream out = response.getOutputStream();
  response.setContentLength((int)length);
 while ((in != null) && ((length = in.read(buf)) != -1)) {
 out.write(buf, 0, (int)length);
    }
     in.close();
    out.close();
    }catch (Exception exc){
    exc.printStackTrace();
    } 

    // fin de la boite de dialogue
     this.setExecuted(true);
     System.out.println("je vais faire le return");
     return "success";
       // facesContext.responseComplete();





        } catch (JRException e) {
        e.printStackTrace();
        return "erreur";
        } catch (SQLException e) {
        e.printStackTrace();
        return "erreur";
        } 
        finally {
            try {

                connection.close();
            } catch (SQLException e) {

                e.printStackTrace();
            }
        }

  }

我的 JSP 页面“ListeAutoTPEs.jsp”

 <h:commandButton value="télécharger" action="#{traitement.toutLesAuto}" >
4

2 回答 2

0

导航规则提到 /listeTransacTelecol.jsp 作为来自 id。与 ListeAutoTPEs.jsp 不匹配。

我不确定是否允许转发到 html,我自己从未尝试过。

于 2012-08-17T11:31:54.517 回答
0

我想您不能转发到纯 HTML 文件。也许您可以将 test2.htm 更改为 JSP 页面并尝试:

<navigation-case>
    <from-outcome>success</from-outcome>
    <to-view-id>/test2.jsp</to-view-id>
    <redirect/>
</navigation-case>

所有其他导航规则是否按预期工作?

于 2012-08-17T11:23:09.640 回答