2

is their a neat way to pass a model to jsp, render the jsp and return the html as string using Spring. The html is then used in an e-mail that is fired off programmitcally, I do not want to use freemarker, but maybe I should ?

The url being requested is part of the same app.

I want one of my service layer classes to be able to call a view and use the html as a String.

3 Answers 3

1

You can call requestDispatcher.include(request, response) method.

You will need to implement the request and response objects. The request object will provide all information to the dispatcher which page should be rendered, the response object you will pass to the call will then capture the result to a string (using e.g. a StringBuilder).

See e.g. this tutorial for more info.

Sign up to request clarification or add additional context in comments.

Comments

0

I'm guessing a servlet filter will do the trick? Not really a Spring solution, but easy enough to do.

Also this answer seems relevant, although it is DWR that you may not necessarily want to use in this instance.

Comments

0

You can use Velocity to create an email template:

String text = VelocityEngineUtils.mergeTemplateIntoString(
           velocityEngine, "emailTemplate.vm", model);

There is a complete chapter in the Spring reference docs of how Spring can be used to send emails of various types.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.