2 Replies Latest reply on May 16, 2008 4:22 PM by yannick bardon

    Problem with servlet

    yannick bardon Newbie

      Hi,


      I'd like to create my own servlet, why, I create a class java in the package of session beans.


      Here is the code of my servlet:



      public class Download extends HttpServlet{
      
           public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
                FacesContext context = FacesContext.getCurrentInstance();
                ExternalContext ec = context.getExternalContext();
                String filePath = null;
                String fileName = null;
                int read = 0;
                byte[] bytes = new byte[1000];
      
                
                response.setContentType("application/pdf");
                response.addHeader("Content-disposition", "attachment; filename=\"" + fileName +"\"");
      
                filePath = "C:\\Yannick\\tutoriaux"; 
                fileName = "jpa.pdf";
      
                try
                {
                     ServletOutputStream os = response.getOutputStream();
                     File file = new File(filePath,fileName);
                     FileInputStream fis = new FileInputStream(file);
      
                     while((read = fis.read(bytes)) != -1)
                     {
                          os.write(bytes,0,read);                       
                     }
      
                     os.flush();
                     context.responseComplete();
                     os.close();
      
                     System.out.println("\nSuccess\n");
                }
                catch(Exception e)
                {
                     System.out.println("\nFailure : " + e.toString() + "\n");
                }
      
      
      
           }
      }
      





      Then I add in the web.xml these lines:



          <servlet>
              <servlet-name>Download</servlet-name>
              <servlet-class>sessionBeans.Download</servlet-class>
          </servlet>
          <servlet-mapping>
              <servlet-name>Download</servlet-name>
              <url-pattern>/Download</url-pattern>
          </servlet-mapping>




      when I try to access my servlet via the url, here is the error that appears in firefox:



      type Rapport d'exception
      
      message
      
      description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la requête.
      
      exception
      
      javax.servlet.ServletException: java.lang.IllegalArgumentException: no file extension in servlet path: /Download
           org.jboss.seam.web.ExceptionFilter.endWebRequestAfterException(ExceptionFilter.java:126)
           org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:70)
           org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      
      cause mère
      
      java.lang.IllegalArgumentException: no file extension in servlet path: /Download
           org.jboss.seam.mock.MockViewHandler.getActionURL(MockViewHandler.java:44)
           org.jboss.seam.jsf.SeamViewHandler.getActionURL(SeamViewHandler.java:74)
           org.jboss.seam.faces.FacesManager.redirect(FacesManager.java:154)
           org.jboss.seam.faces.Redirect.execute(Redirect.java:139)
           org.jboss.seam.exception.DebugPageHandler.handle(DebugPageHandler.java:32)
           org.jboss.seam.exception.Exceptions.handle(Exceptions.java:75)
           org.jboss.seam.web.ExceptionFilter.endWebRequestAfterException(ExceptionFilter.java:114)
           org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:70)
           org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      
      note La trace complète de la cause mère de cette erreur est disponible dans les fichiers journaux de JBossWeb/2.0.1.GA.




      I work with the version of seam 2.0.2.CR1



      where is the problem ?


      Thank you

        • 1. Re: Problem with servlet
          Mark Coffin Newbie

          Do you have the following in your web.xml?



              <filter-mapping>
                  <filter-name>Seam Filter</filter-name>
                  <url-pattern>/*</url-pattern>
              </filter-mapping>



          It looks like the Seam Filter is trying to process the request before it even gets to your servlet.


          I'm still fairly new to Seam myself, so I'm not sure if you can just change it:


              <filter-mapping>
                  <filter-name>Seam Filter</filter-name>
                  <url-pattern>/*.seam</url-pattern>
              </filter-mapping>


          • 2. Re: Problem with servlet
            yannick bardon Newbie

            I made the changes you told me, but there is an error when deploying under jboss:


            <url-pattern> / *.seam invalid