Hi, I've 2 alternately suggestion: 1. Write the code in a jsp file instead of the servlet. 2. in the faces-config.xml file, config the action to an jsp file, write code forward the request to your servlet in the jsp file.
Hope be helpful. David -----Original Message----- From: Raj Saini [mailto:[EMAIL PROTECTED] Sent: Monday, April 10, 2006 7:28 PM To: Jetspeed Users List Subject: Re: Force downloading a file in JSF portlet Vladimir, Thanks for you help till now. I feel I am still missing something. I am not able to forward the control from my JSF page to servlet. My servlet is configured fine and it is working standalone. I searched the web for help on how to forward request to a servlet from JSF page and based on it I call an action method in my JSF page and action method returns a String. <code> public String download() { System.out.println("Inside download method"); return "/knowledge-base/download"; } </code> However, request is never forwarded to servlet. Can you throw some light? Can you tell me how do you forward request from JSF page to servlet? What do you specify in the action attribute of your CommandLink component? Thanks, Raj On 4/10/06, Vladimir Figurov <[EMAIL PROTECTED]> wrote: > 8-O > > It's simple - need add to web.xml next elements: > > <web-app> > ... > <servlet> > <servlet-name>documents</servlet-name> > <servlet-class>asoft.web.Doc_view</servlet-class> > <load-on-startup>1</load-on-startup> > </servlet> > ... > > > <servlet-mapping> > <servlet-name>documents</servlet-name> > <url-pattern>/documents/*</url-pattern> > </servlet-mapping> > ... > </web-app> > > > > > Raj Saini wrote: > > >Hi Vladimir, > > > >My code is inside a ActionListener of CommandLink component of JSF > >and that may be the reason it is not working. I am not able to figure > >out how to forward control to servlet from ActionListener. Can you > >please tell me how do you forward control to servlet from your JSF page? > > > >Regards, > > > >Raj > > > >On 4/10/06, Vladimir Figurov <[EMAIL PROTECTED]> wrote: > > > > > >>Hi Raj, > >> > >>I look your code. I think, it does not work because you use not pure > >>сервлет for loading. I do not see heading of your class - similar > >>that it Faces PageBean? > >> > >> > > > > > > > > > >>I use a combination JSF pages + simple pure Servlet, listening part > >>URL for download: > >> > >> > >> > >>public class Doc_view extends HttpServlet { > >> > >> public void doGet(HttpServletRequest request, HttpServletResponse > >>response) > >> throws ServletException, IOException { > >> String uri = request.getPathInfo(); > >> int pdoc_id=Integer.parseInt(request.getParameter("doc_id")); > >> try { > >> response.setContentType("application/x-download"); > >> response.setHeader("content-disposition", "attachment; > >>name=\""+downloadFileName+"\"; filename=\""+downloadFileName+"\""); > >> byte[] data = .... ; > >> response.setContentLength(data.length); > >> response.getOutputStream().write(data); > >> } catch (Exception e) {... } > >> } > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >>Raj Saini wrote: > >> > >> > >> > >>>Hi Vladmir, > >>> > >>>I tried your suggestion. It did not work for me. I am using apche > >>>my faces JSF bridge. Does it work for you form a JSF based porlet? > >>> > >>>Below the the code snipt of processAction method of command link > >>>action listener. Can you see if I am missing something? > >>> > >>> > >>>============================ > >>> > >>> FacesContext facesContext = FacesContext.getCurrentInstance(); > >>> String path = > >>>facesContext.getExternalContext().getInitParameter("uploadDirectory > >>>Location"); > >>> > >>> Map map = > >>> facesContext.getExternalContext().getRequestParameterMap(); > >>> String fileName = (String) map.get("fileName"); > >>> System.out.println("File URI: " + path+fileName); > >>> > >>> File file = new File(path + fileName); > >>> long fileSize =file.length(); > >>> > >>> //Set the HTTP headers for foce download the file > >>> HttpServletResponse response = > >>>(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse(); > >>> response.setContentType("application/x-download"); > >>> response.setHeader("content-disposition", > >>>"attachment;name=\""+fileName+"\";filename=\""+fileName+"\""); > >>> response.setContentLength((int)fileSize); > >>>========================================================== > >>> > >>>Regards, > >>> > >>>Raj > >>>On 4/10/06, Vladimir Figurov <[EMAIL PROTECTED]> wrote: > >>> > >>> > >>> > >>> > >>>>Hi, > >>>>try next: > >>>> > >>>>response.setContentType("application/x-download"); > >>>>response.setHeader( > >>>>"content-disposition", > >>>>"attachment;name=\""+downloadFileName+"\";filename=\""+downloadFil > >>>>eName+"\""); > >>>> > >>>>for me - it's worked exellent in IE, Opera and Mozilla > >>>> > >>>> > >>>> > >>>> > >>>>Raj Saini wrote: > >>>> > >>>> > >>>> > >>>> > >>>> > >>>>>Hi David, > >>>>> > >>>>>I tried it. It does not work. > >>>>> > >>>>>Thanks, > >>>>> > >>>>>Raj > >>>>> > >>>>>On 4/9/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> > >>>>>>Hi, > >>>>>> > >>>>>>try this code: > >>>>>> > >>>>>>response.setContentType("binary/download"); > >>>>>>response.setHeader("Content-disposition","attachment; > >>>>>>filename=xxx.xxx"); > >>>>>> > >>>>>>before dump the content. > >>>>>> > >>>>>> > >>>>>>Best Regards, > >>>>>> > >>>>>>David > >>>>>> > >>>>>> > >>>>>>-----Original Message----- > >>>>>>From: Raj Saini [mailto:[EMAIL PROTECTED] > >>>>>>Sent: Saturday, April 08, 2006 11:06 PM > >>>>>>To: Jetspeed Users List > >>>>>>Subject: Force downloading a file in JSF portlet > >>>>>> > >>>>>>Hi, > >>>>>> > >>>>>> > >>>>>>I am building JSF based portlet for downloading a file using > >>>>>>MyFaces JSF bridge. > >>>>>>I do the following to make the file force download: > >>>>>> > >>>>>>1) Set "content-disposition" header to contain the correct > >>>>>>filename > >>>>>>2) Set "content-type" header to "application/octet-stream" or > >>>>>>something more accurate if the information is present in > >>>>>>attachment metadata > >>>>>>3) Dump the content using a ServletOutputStream > >>>>>> > >>>>>>When I click on the link to download the file, instead of > >>>>>>throwing a dialog box for saving/opening the file, browser dumps > >>>>>>the the binary contents on page. However, this works fine as standalone > >>>>>>application. > >>>>>> > >>>>>>Is there something extra I need to do to force download file in > >>>>>>Jetspeed? Am I missing something here? > >>>>>> > >>>>>>Regards, > >>>>>> > >>>>>>Raj > >>>>>> > >>>>>> > >>>>>> > >>>>>> > >>>>>>---------------------------------------------------------------- > >>>>>>----- To unsubscribe, e-mail: > >>>>>>[EMAIL PROTECTED] > >>>>>>For additional commands, e-mail: > >>>>>>[EMAIL PROTECTED] > >>>>>> > >>>>>> > >>>>>>---------------------------------------------------------------- > >>>>>>----- To unsubscribe, e-mail: > >>>>>>[EMAIL PROTECTED] > >>>>>>For additional commands, e-mail: > >>>>>>[EMAIL PROTECTED] > >>>>>> > >>>>>> > >>>>>> > >>>>>> > >>>>>> > >>>>>> > >>>>>> > >>>>>> > >>>>>----------------------------------------------------------------- > >>>>>---- To unsubscribe, e-mail: > >>>>>[EMAIL PROTECTED] > >>>>>For additional commands, e-mail: > >>>>>[EMAIL PROTECTED] > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> > >>>>-- > >>>>Vladimir > >>>> > >>>> > >>>>------------------------------------------------------------------ > >>>>--- To unsubscribe, e-mail: > >>>>[EMAIL PROTECTED] > >>>>For additional commands, e-mail: > >>>>[EMAIL PROTECTED] > >>>> > >>>> > >>>> > >>>> > >>>> > >>>> > >>>------------------------------------------------------------------- > >>>-- To unsubscribe, e-mail: > >>>[EMAIL PROTECTED] > >>>For additional commands, e-mail: > >>>[EMAIL PROTECTED] > >>> > >>> > >>> > >>> > >>> > >>> > >>-- > >>Vladimir > >> > >> > >>-------------------------------------------------------------------- > >>- To unsubscribe, e-mail: > >>[EMAIL PROTECTED] > >>For additional commands, e-mail: > >>[EMAIL PROTECTED] > >> > >> > >> > >> > > > -- > Vladimir > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
