1

I am working on a Spring MVC application that sends mail on a button click. I plan to generate the formatted HTML for the email in a JSP. But I am not sure how to get the output of this JSP back into the Controller (without going around the browser)

One way I thought was to make a fresh HTTP request to itself, from within the controller - and get the HTML generated by this JSP. But when I do this, the session changes and I lose the session models.

Is there some way to maintain the session in the HTTP request made.. Or some feature of Spring to handle the whole scenario in a better way?

Get jsp output in spring controller as String .. talks of something similar. But that is still unanswered.

1 Answer 1

1

For session info passing on redirect you can check RedirectAttributes or flash attributes.The moment you say you are using JSP, the control for the view generation goes beyond Spring since the JSP is compiled and translated into servlet and run by servlet container. So the only option is to use any other templating engine to which you can delegate the email content generation by passing all the relevant context and then send that string back as JSON go for harder option of writing custom code for generation.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.