2

これは私のstruts.xmlファイルです。

<action name="sample" class="com.action.getPdf" method="getPdf">
    <result name="success" type="stream">
        <param name="inputName">fileInputStream</param>
       <param name="contentType">application/pdf</param>
        <param name="contentDisposition">attachment;filename="${fileName}"</param>
       <param name="bufferSize">1024</param>
    </result>
 </action>

これは、 のオブジェクトFileが取得されるアクション コードnullです。

public String getPdf()throws Exception
    {
        Session ss = HibernateUtils.getSess();
        Transaction t=ss.beginTransaction();
        HttpSession httpsession=request.getSession();
        String path2=request.getParameter("path1");
          ServletContext servletContext = ServletActionContext.getServletContext();
        //String path3=servletContext.getRealPath(path2);
        System.out.println("the relative path of  the file is:"+path2);
        try
          {             
            File fileToDownload = new File(path2);   
            fileInputStream = new FileInputStream(fileToDownload);                          
          }         
          catch (Exception e)
          {
             if (t!=null) 
             {
                 t.rollback();
                 e.printStackTrace(); 
             }
          }
          finally 
          {
              ss.close(); 
          }         
        return "success";
        }

ダウンロードしたいファイルを Web コンテンツ フォルダに保存し、そのパスをデータベースに保存しました。

4

2 に答える 2