You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andoni <an...@indigo.ie> on 2003/09/10 22:17:31 UTC

jsp -> string ?

Hello,

I have written a little method for my servlet that let's me know when something goes wrong.  It sends me an email the body of which is a simple java.lang.String.  This is easy as I cut mostly from a book I have ;-)

Anyway, my question now is, I want to have my RequestDipatcher fill out a jsp page and send this as the body of the email.  Can anyone tell me how to achieve this?

How do I convert the .jsp with all it's parameters filled in, into a java.lang.String?

My thanks in advance,

Andoni.


Re: Simulating HttpSession

Posted by Jon Wingfield <jo...@mkodo.com>.
Everything can be Mocked ;)
www.mockobjects.com
Specifically the com.mockobjects.servlet package
http://mockobjects.sourceforge.net/javadoc/1.4/

Christopher Williams wrote:
> HttpSession is an interface - implement it yourself.
> 
> ----- Original Message ----- 
> From: "Altuğ B. Altıntaş" <al...@riskturk.com>
> To: "'Tomcat Users List'" <to...@jakarta.apache.org>
> Sent: Thursday, September 11, 2003 11:15 AM
> Subject: Simulating HttpSession
> 
> 
> 
>>Hi, How can i simulate HttpSession. Back side classes uses HttpSession
>>but testing them without Tomcat seems imposible, any idea ?
>>
>>Regards.
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 




Re: Simulating HttpSession

Posted by Christopher Williams <cc...@ntlworld.com>.
HttpSession is an interface - implement it yourself.

----- Original Message ----- 
From: "Altuğ B. Altıntaş" <al...@riskturk.com>
To: "'Tomcat Users List'" <to...@jakarta.apache.org>
Sent: Thursday, September 11, 2003 11:15 AM
Subject: Simulating HttpSession


> Hi, How can i simulate HttpSession. Back side classes uses HttpSession
> but testing them without Tomcat seems imposible, any idea ?
>
> Regards.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



Simulating HttpSession

Posted by "Altuğ B. Altıntaş" <al...@riskturk.com>.
Hi, How can i simulate HttpSession. Back side classes uses HttpSession
but testing them without Tomcat seems imposible, any idea ? 

Regards.



Re: jsp -> string ?

Posted by Bill Barker <wb...@wilshire.com>.
"Pike" <pi...@kw.nl> wrote in message
news:67544F04-E430-11D7-ADF2-000393633FDA@kw.nl...
> Hi
>
> > Can be done.  This example should get you started.
>
> that is a really nice solution !
> one question
>
> >    public class MyEmailResponse extends HttpServletResponseWrapper {
> >       Writer out;
> >        public MyEmailResponse(HttpServletResponse res) {
> >          super(res);
> >          out = new StringWriter();
> >        }
> >        public Writer getWriter() {
> >           return out;
> >        }
> >        // You may need to override some other methods here
> >   };
>
> do you have to override both getWriter() and getOutputStream(), and in
> both,
> check if the other hasn't been called ? how do you know which method
> tomcat or jasper internally uses ?

Without looking, I believe that Jasper only asks for Writer.  Of course, the
only way to know which method Tomcat and/or Jasper internally uses is to
downlowd the source distro, and start poking around (of course, the downside
of this is that you might end up being a Tomcat committer, and having to
deal with questions like this ;-).

>
> > Then in your servlet:
> >
> >       MyEmailResponse mer = new MyEmailResponse(response);
> >       RequestDispatcher rd =
> > getServletContext().getRequestDispatcher("/myEmail.jsp");
> >       rd.include(request, mer);
> >       mer.flushBuffer();
> >       StringWriter sw = (StringWriter)mer.getWriter();
> >       String emailMessage = sw.toString();
>
>
> thanks,
> *pike
>
> ========================
> = 1/9671406556917033397649408 yottabyte
> = 1/9444732965739290427392 zettabyte
> = 1/9223372036854775808 exabyte
> = 1/9007199254740992 petabyte
> = 1/8796093022208 terabyte
> = 1/8589934592 gigabyte
> = 1/8388608 megabyte
> = 1/1048576 Megabit
> = 1/8192 kilobyte
> = 1/1024 Kilobit
> = 1/8 byte
> = 1/4 nibble
> bit = 1 bit




Re: jsp -> string ?

Posted by Pike <pi...@kw.nl>.
Hi

> Can be done.  This example should get you started.

that is a really nice solution !
one question

>    public class MyEmailResponse extends HttpServletResponseWrapper {
>       Writer out;
>        public MyEmailResponse(HttpServletResponse res) {
>          super(res);
>          out = new StringWriter();
>        }
>        public Writer getWriter() {
>           return out;
>        }
>        // You may need to override some other methods here
>   };

do you have to override both getWriter() and getOutputStream(), and in 
both,
check if the other hasn't been called ? how do you know which method
tomcat or jasper internally uses ?

> Then in your servlet:
>
>       MyEmailResponse mer = new MyEmailResponse(response);
>       RequestDispatcher rd = 
> getServletContext().getRequestDispatcher("/myEmail.jsp");
>       rd.include(request, mer);
>       mer.flushBuffer();
>       StringWriter sw = (StringWriter)mer.getWriter();
>       String emailMessage = sw.toString();


thanks,
*pike

========================
= 1/9671406556917033397649408 yottabyte
= 1/9444732965739290427392 zettabyte
= 1/9223372036854775808 exabyte
= 1/9007199254740992 petabyte
= 1/8796093022208 terabyte
= 1/8589934592 gigabyte
= 1/8388608 megabyte
= 1/1048576 Megabit
= 1/8192 kilobyte
= 1/1024 Kilobit
= 1/8 byte
= 1/4 nibble
bit = 1 bit


Re: jsp -> string ?

Posted by Bill Barker <wb...@wilshire.com>.
Can be done.  This example should get you started.
   public class MyEmailResponse extends HttpServletResponseWrapper {
      Writer out;
       public MyEmailResponse(HttpServletResponse res) {
         super(res);
         out = new StringWriter();
       }
       public Writer getWriter() {
          return out;
       }
       // You may need to override some other methods here
  };

Then in your servlet:

      MyEmailResponse mer = new MyEmailResponse(response);
      RequestDispatcher rd =
getServletContext().getRequestDispatcher("/myEmail.jsp");
      rd.include(request, mer);
      mer.flushBuffer();
      StringWriter sw = (StringWriter)mer.getWriter();
      String emailMessage = sw.toString();

"Andoni" <an...@indigo.ie> wrote in message
news:004101c377d8$90a91ff0$39e1a8c0@HOLODECK...
Hello,

I have written a little method for my servlet that let's me know when
something goes wrong.  It sends me an email the body of which is a simple
java.lang.String.  This is easy as I cut mostly from a book I have ;-)

Anyway, my question now is, I want to have my RequestDipatcher fill out a
jsp page and send this as the body of the email.  Can anyone tell me how to
achieve this?

How do I convert the .jsp with all it's parameters filled in, into a
java.lang.String?

My thanks in advance,

Andoni.