How do I pass get request parameters to my Velocity Template to send mails

こ雲淡風輕ζ 提交于 2019-12-01 23:21:26

The solution is the Velocity context. In your backing Java class or Velocity servlet, read in the parameters and put them in the context:

context.put("email", request.getParameter("email"));
context.put("id", request.getParameter("id"));

Then in your Velocity template you can reference them as $email and $id.

In the accepted answer you have to explicitly unwind all the arguments in your controller. So if you have 5 fields, you have 5 of the above statements.

I would suggest:

context.put("request", request);

Then in your template something like this:

<p>Is the Jump Run Heading Good? <b>$request.getParameter("heading")</b></p>  

Maybe you could write a little macro to avoid that last little bit of ugliness. You write a little helper function to loop through the request parameters names with getParameterNames() and call getParameter() on each.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!