Sending a dynamic jsp/html page as an email. - html

Posted this in another forum, thought of posting here as well.
I need to send a jsp/html page, that is generated as a report, as an email. How do I do it?
If it's a static html page, I can hard code it as a string variable and set it as one of the arguments in the setContent method as follow:
message.setContent(stringValue,"text/html"), but how do I do it for a page that is actually a report, meaning it's contents are dynamic. Hope somone can help. Thank you.

Use a templating engine, like Velocity, to dynamically replace variables. Depending on tools and frameworks you already use, there might even be some ready-made helper classes. I know Spring has emailing features with built-in Velocity support.

Related

Can I input a variable into HTML and give it to CSS to update a gauge reading?

I am trying to write a bit of code to read a sensor and, with my ESP32 make a webpage that will display the value.
But on a gauge with a "needle" ( think speedometer type of thing ) like output, I can make variables in CSS and I can make the gauge in CSS and display in HTML fine.
I can change the value of the gauge by changing the CSS variable BUT I want to be able to pass this varibale to CSS from my HTML file.
This is so I can process the HTML page on my ESP32, updating the value of the sensor and display it, I can't seem to get an option of updating CSS varible through HTML.
I would like to rather stay away from JavaScript to be hoest, I'm already learning CSS and HTML to make this work, but if need be I will do it.
Or could I do this in PHP perhaps ?
Any advice ?
If you want to make this dynamic, you have no other option rather than to recur to JavaScript in combination with what you are using. From what I understand it's something like either a percentage value or a rotation degree value you are toying around with.
What I can recommend for your specific case is to use an inline style to change the position of your indicator.
Something like:
<div style="width: 99%;"></div>
It would help if you share with us what you have as code till now.
Also, from what I understand you are still new to this sort of coding, but something that would probably work really well for you could be Socket.io you just assign a port that receives information and configure it, and you could configure your ESP32 to send info to that port I suppose, not really familiar with that part though.
If you want really real time value refreshing with esp32 on its own web you have to use websockets.
I don't know what server library you using, but there are a couple of websocket libaries out there.
I recommend ESP32_AsyncWebserver from Me_no_Dev. This is a fully async webserver implementation, and it is containing the async websocket too.
If you succesfully implemented that to your project, and loaded your static html file with the gauge you mentioned, on runtime of the esp32 you can send websocket text messages to the front-end javascript code. Once you received the messages on the javascript side you can easily update anything from there.
If you interested in this more, i will write some code for you in here. Just let me know.

HTML Form: Can submitted GET/POST parameters be suppressed using only HTML or CSS?

I am volunteering on a website-based project that is trying to make all pages fully operable JavaScript free before adding any JavaScript for enhancements, and I was asked to investigate whether or not a particular scenario could be handled purely through HTML/CSS.
What we have is a form that is populated to help us filter a list of tickets that are displayed on the screen after a page update through a GET action, which itself works fine, but the concern with the current implementation is that the URL cannot be made into a permanent link. The request, however, to keep the permanent link as minimal as possible, is to only send GET parameters for fields that are populated with something (so, suppressing GET parameters for fields that are blank) instead of having a different GET parameter for each form field on the page.
I have thought of several ways that could be done, most including JavaScript (example: create fields with ids but no names and a hidden field w/ name that uses JS to grab the data from the fields), but also one that would be a POST action with a redirect back to the GET with a human readable string that could be permanently used. The lead dev, however would prefer not to go through the POST/redirect method if at all possible.
That being said, I'm trying to make sure I cover all my bases and ask experts their thoughts on this before I strongly push for the POST/redirect solution: Is there a way using only HTML & CSS to directly suppress GET parameters of a form for fields that are blank without using a POST/redirect?
No, suppressing fields from being submitted in an HTML form with method of "GET" is not possible without using JavaScript, or instead submitting the form with a POST method and using a server side function to minimize the form.
What fields are submitted are defined by the HTML specification and HTML and CSS alone cannot modify this behavior and still have the browser be compliant with the standards.
No, you cannot programmatically suppress any default browser behavior without using some kind of client scripting language, like JavaScript.
As a side note, you say "JavaScript for enhancements", but JavaScript is not used for enhancements these days. And no one in the real world would except a decent front-end without the use of JavaScript. I would suggest you simply use JavaScript.
I do not think you can avoid Javascript here to pre process before submission to eliminate unchanged /empty form fields.

Semantic Media Wiki: Displaying a SVG element of a HTML page

I have a HTML page that displays a SVG element (a Business process diagram) using some javascript libraries. A String variable, say 'str' needs to be given to html function.
After reading this, I plan to use widgets. So far I understand that I need to copy all scripts to Widgets: Test. For creating the hook, I write
{{#widget:Test|str=UserTask_1}}
The problem is that UserTask_1 is a variable as well. It is different each time.
Can someone help how can I add this dynamic information to my hook? This hook is a hyperlink from a previous page. In the previous page, I send the str=UserTask_1 through JavaWiki Bot.
PS: I have come-across SMW for first time. Please excuse if my language is not very technical at the moment.
Thanks.

Localizing a Google Chrome Web App

I'm trying to add localization support to a Google Chrome Web App and, while it is easy to define strings for manifest and CSS files, it is somewhat more difficult for HTML pages.
In the manifest and in CSS files I can simply define localization strings like so:
__MSG_name__
but this doesn't work with HTML pages.
I can make a JavaScript function to fire onload that does the job like so:
document.title = chrome.i18n.getMessage("name");
document.querySelector("span.name").innerHTML = chrome.i18n.getMessage("name");
but this seems awfully ineffecient. Furthermore, I would like to be able to specify the page metadata; application-name and description, pulling the values from the localization files. What would be the best way of doing all this?
Thanks for your help.
Please refer to this documentation:
http://code.google.com/chrome/extensions/i18n.html
If you want to add localized content within HTML, you would need to do it via JavaScript as you mentioned before. That is the only way you can do it.
chrome.i18n.getMessage("name")
It isn't inefficient to do that, you can place your JavaScript at the end of the document (right before the end body tag) and it will fill up the text with respect to the locale.
Dunno if i understand exactly what you are trying to do but you could dynamically retrieve the LANG attribute (using .getAttribute("lang") or .lang) of the targeted tag and serve accordingly the proper values.

What is the best way to create printable letters from an MVC application?

What's the best way to create printable letters from an MVC application? I'm looking for sort of a mail merge thing from my app that prints a form letter with various values filled in.
In ASP.NET, I previously did this by creating an HTML document and displaying it as application/msword, but I did that with code-behind, which isn't an (easy) option in MVC, and I don't know if that's the best method or not.
Note that this is an internal application, so it can be assumed everyone has Word on their computer. With that said, it would be nice to bypass Word, but I could go either way. The simpler the better. Any ideas/methods welcome.
Since this is just HTML with the ContentType set to application/msword I can't see any reason why you would want to use code-behind.
A standard MVC view with a typical HTML template peppered with appropriate <%=...> where view data needs to be inserted would seem to be the sensible approach. Even where you might want to loop.
BTW, why isn't code-behind an easy option?
In your controller:
return Content(contentGoesHere, "application/msword");