struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nils-Helge Garli Hegvik <nil...@gmail.com>
Subject Re: Get jsp content in struts action
Date Wed, 11 Mar 2009 09:29:22 GMT
I don't know how to solve your problem, but you can look at this
thread for some good advice:
http://www.mail-archive.com/user@struts.apache.org/msg85536.html

Maybe you'll find this useful as well:
http://forums.sun.com/thread.jspa?threadID=730559&messageID=4220069

Nils-H

On Tue, Mar 10, 2009 at 8:10 AM, D1vy@@Ind1@
<divya.rajendranath@gmail.com> wrote:
>
> Our application is a simple online form, in which users enters details about
> various books maintained in a library, hence when updated/new editions of
> book arrive, we would be mailing the concerned people about the updated
> version of the book. Before the user updates the existing record, when he
> click preview he could see the details of the book, with the changes in the
> edition highlighted. Now when these details are mailed programmatically (the
> content would be the same they see in the preview page with the changes
> highlighted), hence we wanted to call the JSP from the Struts action class.
>
> -D
>
>
> Nils-Helge Garli wrote:
>>
>> Why do you need the contents of the JSP? I'd consider a Servlet Filter
>> instead if you need to process the output before it's returned to the
>> browser.
>>
>> Nils-H
>>
>> On Tue, Mar 10, 2009 at 7:29 AM, D1vy@@Ind1@
>> <divya.rajendranath@gmail.com> wrote:
>>>
>>> Hmm.. I am not sure if the code is problematic because with the same code
>>> I
>>> am able to read the contents of all JSP pages. Only for JSPs using struts
>>> tags I get an exception as mentioned previously, I wanted to know how can
>>> I
>>> get rid of that exception.
>>>
>>> -D
>>>
>>>
>>> mgainty wrote:
>>>>
>>>>
>>>> the input stream comes from Request
>>>> the output stream comes from Response response.getOutputStream();
>>>> http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletResponse.html#getOutputStream()
>>>>
>>>> this code is problematic as it is NOT associated with output stream from
>>>> HttpServletResponse response
>>>>
>>>>>                      baos = new ByteArrayOutputStream();
>>>>>                      pw = new PrintWriter(baos);
>>>>
>>>> Martin
>>>> ______________________________________________
>>>> Disclaimer and confidentiality note
>>>> Everything in this e-mail and any attachments relates to the official
>>>> business of Sender. This transmission is of a confidential nature and
>>>> Sender does not endorse distribution to any party other than intended
>>>> recipient. Sender does not necessarily endorse content contained within
>>>> this transmission.
>>>>
>>>>
>>>>
>>>>
>>>>> Date: Fri, 6 Mar 2009 05:32:21 -0800
>>>>> From: divya.rajendranath@gmail.com
>>>>> To: user@struts.apache.org
>>>>> Subject: Get jsp content in struts action
>>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> I have a JSP with struts tags in it. I want to get its contents from
>>>>> the
>>>>> struts action class. I did it using RequestDispatcher.
>>>>>
>>>>> I wrote the following code ..
>>>>>
>>>>> ======
>>>>>      // Creates a response wrapper object.
>>>>>      BufferedHttpResponseWrapper responseWrapper = new
>>>>> BufferedHttpResponseWrapper(response);
>>>>>
>>>>>      // Creates a requestDispatcher object.
>>>>>      ServletContext sc = request.getSession().getServletContext();
>>>>>      String url =
>>>>> response.encodeRedirectURL("/web/jsp/osf/ShowStaffingForm.jsp");
>>>>>      RequestDispatcher dispatcher = sc.getRequestDispatcher(url);
>>>>>      try {
>>>>>              dispatcher.include(request,responseWrapper);
>>>>>      } catch (Exception e) {
>>>>>              e.printStackTrace();
>>>>>      }
>>>>>      try {
>>>>>              String result = new String(responseWrapper.getOutput());
>>>>>              System.out.println("Result :: "+result);
>>>>>      } catch (Exception e) {
>>>>>              System.out.println("Exception occurring here...");
>>>>>              e.printStackTrace();
>>>>>      }
>>>>>
>>>>>             //This is the reponse wrapper class.
>>>>>               /*
>>>>>               * BufferedHttpResponseWrapper class
>>>>>       *       *
>>>>>       */
>>>>>      public class BufferedHttpResponseWrapper extends
>>>>> HttpServletResponseWrapper
>>>>> {
>>>>>
>>>>>              PrintWriter pw = null;
>>>>>              ByteArrayOutputStream baos = null;
>>>>>
>>>>>              public BufferedHttpResponseWrapper(HttpServletResponse
>>>>> response) {
>>>>>
>>>>>                      super(response);
>>>>>                      baos = new ByteArrayOutputStream();
>>>>>                      pw = new PrintWriter(baos);
>>>>>              }
>>>>>
>>>>>              public PrintWriter getWriter() throws IOException
{
>>>>>                      return pw;
>>>>>              }
>>>>>
>>>>>              public String getOutput() {
>>>>>                      pw.flush();
>>>>>                      pw.close();
>>>>>                      return baos.toString();
>>>>>              }
>>>>>
>>>>>      }
>>>>>
>>>>>
>>>>> I get the jsp content in my log files, but I get an exception on the
>>>>> browser
>>>>> when I call this action.
>>>>> Please note that when the JSP has simple HTML tags i get the content
>>>>> with
>>>>> _no_ exception. Even when the JSP contains some custom tags which I
>>>>> developed , then also there is no exception I get the content. The
>>>>> problem
>>>>> is only when there is Struts tags in the JSP, though I get the content,
>>>>> I
>>>>> get the exception on the browser.
>>>>>
>>>>> The following is the exception:
>>>>>
>>>>> ==========================================================
>>>>>
>>>>> type Exception report
>>>>>
>>>>> message
>>>>>
>>>>> description The server encountered an internal error () that prevented
>>>>> it
>>>>> from fulfilling this request.
>>>>>
>>>>> exception
>>>>>
>>>>> javax.servlet.ServletException: Stream closed
>>>>>
>>>>> org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
>>>>>
>>>>> org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
>>>>>
>>>>> org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99)
>>>>>      jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:147)
>>>>>
>>>>> root cause
>>>>>
>>>>> java.io.IOException: Stream closed
>>>>>
>>>>> org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:203)
>>>>>
>>>>> org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:113)
>>>>>
>>>>>  org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:171)
>>>>>
>>>>> org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
>>>>>
>>>>> org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:601)
>>>>>
>>>>> org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:119)
>>>>>
>>>>> org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
>>>>>
>>>>> org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:186)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>>>>>
>>>>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>>>>>
>>>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>>>>>
>>>>> org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
>>>>>
>>>>> org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
>>>>>
>>>>> org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
>>>>>
>>>>> org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99)
>>>>>      jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:147)
>>>>>
>>>>> =========================================================================
>>>>>
>>>>>
>>>>> Could any one please help me with this.
>>>>>
>>>>> Thanks
>>>>> -D
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Get-jsp-content-in-struts-action-tp22372538p22372538.html
>>>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>
>>>> _________________________________________________________________
>>>> Hotmail® is up to 70% faster. Now good news travels really fast.
>>>> http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_70faster_032009
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Get-jsp-content-in-struts-action-tp22372538p22428755.html
>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Get-jsp-content-in-struts-action-tp22372538p22429077.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message