action forward to servlet
Hello Is/how it possible to forward from a action to a servlet at another url and preserve the parameters and session objects? I am doing all the processing in the Action and just simply need to send a data stream back. I can do it with servlets, but cant seem to do it with an action and a servlet. Can someone help me understand? tia.
Re: action forward to servlet
Preserver de session? Session is already preserved. Did you try that? To get values from session in your servlet you must use Session ses = request.getSession(). Than you have your session object. Parameters from request? You should use request.getParameters(). To get Action fields, well I'm not sure what struts you're using, but maybe you can use ActionContext class to get that. Regards, Felipe cpanon wrote: Hello Is/how it possible to forward from a action to a servlet at another url and preserve the parameters and session objects? I am doing all the processing in the Action and just simply need to send a data stream back. I can do it with servlets, but cant seem to do it with an action and a servlet. Can someone help me understand? tia. -- View this message in context: http://www.nabble.com/action-forward-to-servlet-tf3668811.html#a10253751 Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: action forward to servlet
The first question should be, do you really need the servlet? You could generate the full response from the action. If you still need to keep the servlet around for other uses, perhaps you can refactor the bulk of its work into a service class that both the servlet and the action can use to generate the response. Failing that, the way to do this is to manually dispatch to the servlet (using request.getDispatcher(/servlet/path).forward() or something like that; I forget the exact API). Then be sure to return 'null' from your action to tell Struts it shouldn't do anything further with the response. HTH, L. Felipe Rodrigues wrote: Preserver de session? Session is already preserved. Did you try that? To get values from session in your servlet you must use Session ses = request.getSession(). Than you have your session object. Parameters from request? You should use request.getParameters(). To get Action fields, well I'm not sure what struts you're using, but maybe you can use ActionContext class to get that. Regards, Felipe cpanon wrote: Hello Is/how it possible to forward from a action to a servlet at another url and preserve the parameters and session objects? I am doing all the processing in the Action and just simply need to send a data stream back. I can do it with servlets, but cant seem to do it with an action and a servlet. Can someone help me understand? tia. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: action forward to servlet
Hi Felipe Thanks, that I got. My conceptual difficulty is I dont see how to define a global forwards for the servlet and call it in my request.mapping.FindForward(forwardToServlet), or maybe it is brain-fade Felipe Rodrigues [EMAIL PROTECTED] wrote: Preserver de session? Session is already preserved. Did you try that? To get values from session in your servlet you must use Session ses = request.getSession(). Than you have your session object. Parameters from request? You should use request.getParameters(). To get Action fields, well I'm not sure what struts you're using, but maybe you can use ActionContext class to get that. Regards, Felipe cpanon wrote: Hello Is/how it possible to forward from a action to a servlet at another url and preserve the parameters and session objects? I am doing all the processing in the Action and just simply need to send a data stream back. I can do it with servlets, but cant seem to do it with an action and a servlet. Can someone help me understand? tia. -- View this message in context: http://www.nabble.com/action-forward-to-servlet-tf3668811.html#a10253751 Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: action forward to servlet
Hi Laurie I had used Request.dispatcher before but only in servlet code; didnt know/realize I could do it in an Action. I see the key is to make that one of the states that will always be called and just trick Struts with the return of the null. I assume the technology is orthogonal enough that if I have a browser page, or open a url to the Action it will be automatically be fed the output of the Request.dispatcher from the servlet. That would be very elegant. Laurie Harper [EMAIL PROTECTED] wrote: The first question should be, do you really need the servlet? You could generate the full response from the action. If you still need to keep the servlet around for other uses, perhaps you can refactor the bulk of its work into a service class that both the servlet and the action can use to generate the response. Failing that, the way to do this is to manually dispatch to the servlet (using request.getDispatcher(/servlet/path).forward() or something like that; I forget the exact API). Then be sure to return 'null' from your action to tell Struts it shouldn't do anything further with the response. HTH, L. Felipe Rodrigues wrote: Preserver de session? Session is already preserved. Did you try that? To get values from session in your servlet you must use Session ses = request.getSession(). Than you have your session object. Parameters from request? You should use request.getParameters(). To get Action fields, well I'm not sure what struts you're using, but maybe you can use ActionContext class to get that. Regards, Felipe cpanon wrote: Hello Is/how it possible to forward from a action to a servlet at another url and preserve the parameters and session objects? I am doing all the processing in the Action and just simply need to send a data stream back. I can do it with servlets, but cant seem to do it with an action and a servlet. Can someone help me understand? tia. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]