• Post Reply Bookmark Topic Watch Topic
  • New Topic

Explicitly Process JSP from within a Servlet Container.

 
Guy Yafe
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am looking for a way to have a Servlet (my container is Tomcat) calling a JSP file and processing it in order to retrieve the generated HTML.
The compete scenario:
I have virtual shop and whenever a purchase is being carried out, the customer is redirected to a Servlet that post-processes the purchase (thank you, list of the items, etc.)
Among all these, the Servlet is also supposed to send me an email about the new purchase.
I would like to have nice designed HTML mail and not just a simple plain text notification.
I thought of having a designated JSP as a view, and it will only be available from the Servlet container, for this purpose.
One way is having the Servlet create an HTTPClient (or any other method of network communication) to my own host and ask for the JSP.
I wonder if there is a simpler way to ask my own container to process a JSP, since I am not really making a request to an outside web application.
Something like getServletContext.processAndReturnJsp("mail.jsp")
BTW, if you think my approach is too cumbersome to fill an email with HTML code, it would be great to know of a simpler way.

Thanks,
Guy
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to consider using a templating language more suited to your needs such as FreeMarker.
 
Guy Yafe
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you,
I have never heard of FreeMark, but looks like it does exactly what I am asking.
But still it looks odd to me that I need a third party utility, and can't do the same with Tomcat.

Guy
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably can figure out a way to do it, but it's not what JSP was intended for and it's unlikely to be straightforward. Why jump though hoops when there are tools to do exactly what you want?
 
Guy Yafe
Greenhorn
Posts: 24
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now that I think about it, Tomcat's engine translates a JSP into a Servlet and only than returns the HTML inside an HTTP response, which is exactly what I don't want to do.
So your solution is indeed the best one.
Thanks again.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!