I retrieving the Off time of a page and returning offtimeQuery.toString() and retrieving the page title String resultPageTitle = resultPage.getTitle(); using java.
I am sending an email to the content authors of all the pages which have reached off time. How do i display this off time and page name in my HTML email using javascript?
It is near impossible to make an email with JS in it. If you do manage, then half of the email clients will tear it apart to protect to client-side computer.
Instead, I assume that you are using a Linux box for hosting, you could do two things that would work. Use a bash file or equivalent to dynamically create the page and then fire it off at given times, followed immediately by an email that serves the HTML of that page. That is pretty easy.
The other way would be to use a JS file to do the same. This could work through either time-based(HARD) or by you accessing the page through a browser when you wanted it to go. Again, dynamically create the page with JS and then use the system to send the HTML of the page.
Don't use javascript. Almost all HTML email clients will not run any Javascript, because it is a huge security hole.
Instead put the relevant data into the body of the email as you construct it in your Java code. Presumably you have, in your Java code, those bits of data, and you have the HTML content you're sending as an email. Insert the data there, at most basic using String.format(template, data, ...). But if you are going to do anything other than trivial replacement, use a proper HTML templating system.
Don't try to include any javascript with a HTML email. You may be able to find an email client where it works, but won't for most of your clients.
Javascript gets stripped from email messages due to concerns with security. You could force a redirect and perform phishing attacks, and steal other nasty info such as cookies from the domain that the email was sent to if Dynamic emails were made possible with javascript.
If you are really interested in displaying dynamic content, and don't care how, think about creating a server script which returns an image. You could pass a static identifier to the script, and it could return a dynamic result.
See my project in php at https://github.com/TabLand/EmailTracker which generates dynamic images. Only the time string is dynamic. I'd show you the demonstration, but would end up logging your useragent and IP address!
Related
I'm building my own HTTP server in java, but i'm facing with a problem: I would like to build a page dynamically by creating every HTML object at runtime, the question is: how can i determine the screen dimension of the client's browser?
This information is not present in the HTTP header, so I was thinking about writing a "fake" webpage that runs a javascript that tells the server about the screen (it should redirect to something like www.website.com/w:1920,h:1080) but I don't know anything about cookies (that I suppose are essential to store those informations).
Do you think that I should learn somthng about cookies or there's another way?
BTW I'm not using servlets, just Socket, because that's what I know... should I use servlets?
Thanks for your time!
Matteo
Server knows nothing about client's screen until client send this information. Javascript is easiest way to determine screen size:
window.screen.availHeight
window.screen.availWidth
AJAX request can be used to send the information to the server where it can be stored in session data and backed in database for example if the user is logged in or identified somehow. In such case you don't need cookies. However solution with cookies is easier, check how to set them via javascript. But I'm afraid such solution would be a bit of non-standard, if your site is gonna depend on javascript why not to use it extensively and generate all objects on client side, get that lazy computer working and save your server's resources :) Just feed data by sending simplest HTML containing script doing the work.
Servlets? Can be really light-weight and done with minimal knowledge if you have time go for it.
I am trying to programmatically generate lotusscript (in a form of a scriptable button) from a web application (Java EE) and send it to an end-user who will then run it in his/her Lotus Notes client.
How can I achieve this? Is there an API for me to use in order to embed lotusscript in an email?
Rather than trying to embed a button, I would consider taking advantage of the 'stored form in document' feature of Notes.
I.e., using Domino Designer I would manually create a database (I'll call it "MyDb.nsf" for convenience). Create a form in this database ("MyForm" for convenience) and set it up with the required fields for an email message (SendTo, Subject, Body, etc.). Then create a button on the form and enter the LotusScript code.
With this done in advance, your code can take advantage of the optional attachForm parameter in the Document.send() method.
What you would do is open MyDb.nsf in the usual way, then use Database.createDocument() to create your document in that database, then use Document.ReplaceItemValue("Form","MyForm") to bind this document to your form. Also set the other Items (e.g., Subject, SendTo, Body) as needed, and when you're all done call Document.send(true). This will embed your form in the document and send it, so the LotusScript code will travel in the embedded form that is sent with the message.
I think this might be the best method for you, because I think that this will preserve the signature on the form when it embeds it. I'm not sure about that, but on the other hand I'm much more certain that any other way of sending with CORBA/IIOP will give you an unsigned script (because CORBA/IIOP has no access to the private key needed to sign the document). And an unsigned script will mean that your users get ECL warnings when they execute it -- and that could result in them adding an entry to their ECL to permit unsigned scripts, and that's a bad security practice.
Here is an idea. I haven't tried it and am not certain that it will work:
Create form with a LotusScript button in Domino Designer and set to be stored in the document
Create a document with that form
Export the document as DXL (Domino XML)
In your Java EE application use ncso.jar to import the DXL (you can modify the LotusScript in the XML first as needed)
Email the document using Document.send(). When connected to Domino server with CORBA/IIOP, I think this should work.
Update
You might be able to skip the DXL part and just modify the LotusScript in the document item. I understood that you have to modify the LotusScript for each recipient. If not then everything is much easier (see Richards answer).
Another option is to embed a URL to open a Page design element with your code (or a call to the agent) in the QueryOpen, so it runs when the page opens.
Notes://myserver.mycompany.com/utilities.nsf/MyTaskLauncher?OpenPage
I'm not sure if it could pass parameter values or if you have to rely on the user's credentials to determine the proper information.
Advantages:
Code resides in one location, so I can update it if I find out there
was a bug in the original version.
Minimal manipulation of the user's mail file with stored forms.
Smaller email message, since I don't have to send along form
information.
Easier to build a simple string in Java EE than the higher-powered
solutions.
The agent can either use the signing ID or run with the user's
credentials.
Can be sent to any email address, so long as the recipient has a Notes client.
Requirement is to keep a copy of complete web page at server side same as it is rendered on client browser as past records.These records are revisited.
We are trying to store the html of rendered web page. The html is then rendered using resources like javascript, css and image present at server side. These resources keep on changing. Therefore old records are no longer rendered perfectly.
Is there any other way to solve above? We are also thinking converting it into pdf using IText or apache FOP api but they does not consider javascript effect on page while conversion. Is there any APIs available in java to achieve this?
Till now, no approach working perfectly. Please suggest.
Edit:
In summary,requirement is to create a exact copy of rendered web page at server side to store user activities on that page.
wkhtmltopdf should do this quite nicely for you. It will take a URL, and return a pdf.
code.google.com/p/wkhtmltopdf
Example:
wkhtmltopdf http://www.google.com google.pdf
Depending on just how sophisticated your javascript is, and depending on how faithfully you want to capture what the client saw, you may be undertaking an impossible task.
At a high level, you have the following options:
Keep a copy of everything you send to the client
Get the client to return back exactly whatever it has rendered
Build your system in such a way that you can actually fetch all historical versions of the constituent resources if/when you need to reproduce a browser's view.
You can do #1 using JSP filters etc, but it doesn't address issues like the javascript fetching dynamic html content during rendering on the client.
Getting the client to return what they are seeing (#2) is tricky, and bandwidth intensive.
So I would opt for #3. In order to turn a website that renders dynamic content versioned, you have to do several things. First, all datasources need to versioned too. So any queries would need to specify the version. "Version" can be a timestamp or some generation counter that you maintain. If you are taking this approach, you would also need to ensure that any javascript you feed to the client does not fetch external resources directly. Rather, it should ask for any resources from your system. Your system would in turn fetch the external content (or reuse from a cache).
The answer would depend on the server technology being used to write the HTML. Are you using Java/JSPs or Servlets or some sort of an HTTPResponse object to push the HTML/data to the browser?
If only the CSS/JS/HTML are changing, why don't you just take snapshots of your client-side codebase and store them as website versions?
If other data is involved (like XML/JSON) take a snapshot of those and version that as well. Then the snapshot of the client codebase as mentioned above with the contemporary snapshot of the data should together give you the exact rendering of your website as at that point of time.
A very resource-consuming requirement but...
You haven't written what application server you are using and what framework. If you're generating responces in your own code, you can just store it while generating.
Another possibility is to write a filter, that would wrap servlet's OutputStream and log everything that was written to it, you must just assure your filter is on the top of the hierarchy.
Another, very powerfull, easiest to manage and generic solution, however possibly the most resource-consuming: write transparent proxy server staying between user and application server, that would redirect each call to app server and return exact response, additionally saving each request and response.
If you're storing the html page, why not the references to the js, css, and images too?
I don't know what your implementation is now, but you should create a filesystem with all of the html pages and resources, and create references to the locations in a db. You should be backing up the resources in the filesystem every time you change them!
I use this implementation for an image archive. When a client passes us the url of an image we want to be able to go back and check out exactly what the image was at that time they sent it (since it's a url it can change at any time). I have a script that will download the image as soon as we receive the url, store it in the filesystem, and then store the path to the file in the db along with other various details. This is similar to what you need, just a couple more rows in your table for the js, css, images paths.
In java, is there any way to get the content of a webpage, wich is an .ASPX file.
I know how to read/write anything from a normal HTML page, but asp pages seem to have one URL for multiple pages, so it's not really possible to reach the desired page by URL.
I understand you can't/won't give me complete instructions right here, but could you maybe send me in the right direction ?
Thanks in advance.
There is nothing special about ASPX pages compared to any other type of page; "plain" html pages could have been dynamically generated as well.
Just don't forget that the query string is also part of the URL. Many ASPX, PHP, etc pages might not even be 'correct' to request without some query string value at all. And other sites don't have file extensions at all... like this site itself. You just have to be sure to get the entire URL for each unique 'page'.
I'm not an expert on .asp, so I might be wrong. However, my impression is that a .asp page should ultimately return HTML (similarly to what a .jsp page does), so you can fetch the content in the same way as you would do for an HTML page.
However, you write that
asp pages seem to have one URL for multiple pages
this makes me think that perhaps your .asp page is using AJAX and so the page content may change while the URL doesn't. Is this your case?
I understand that you are trying to read the aspx from a client PC, not from the server.
If that's right, accessing an HTTP resource is independent from the technology used by the server, all you need to do is to open an http request and retrieve the results.
If you see multiple pages from one URL, then one of the following is happening:
1) POST data is sent to the aspx, and it renders different HTML due to these parameters
2) You are not looking really at the inner page but to a page that provides the frames for the HTML being rendered
3) The page uses heavily Ajax in order to be rendered. The "contents" of the page are not download through the initial request but later by javascript.
Generally, it is probably the first reason.
I have a requirement to read and write bulk of text files at server side.
How can we write using Ajax, Java... Have little bit idea about these technologies but I just need an idea to implement. After that I feel I can proceed. Could you please help me?
Firstly the text files are going to have to be publicly accessible. They cannot exist in a private context on the server, as JavaScript is a client side technology.
Once they are public, you can simply do an AJAX request on the file location, and then parse them as required.
If having them in a public location is going to be a problem, you will need to have a page that serves them to authenticated accounts only, so only people that are logged in can view them. This means they will have to be served via a server side script at some point, which the AJAX request can then fetch as required.
However if you take this approach, you might as well take out the AJAX and just have the server side script do the processing for you and feed out the result.