• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Explicitly Process JSP from within a Servlet Container.

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My pleasure!
 
reply
    Bookmark Topic Watch Topic
  • New Topic