I have written a web app with a few JSP pages and Java servlets running on a Tomcat server. The app needs to be able to send location updates to one of the Servlets every x seconds. I have found the html5 watchPosition(sucess_callback, error_callback) function to get the location updates from the web page. I'm thinking.. once I get the update from this function.. I'll put code in the callback function to send the update to a Servlet. But adding the watchPosition function to every JSP page in the app seems cumbersome. What is the right way to send periodic GPS updates to the server no matter whatever webpage the user is viewing in the app?
I'm not sure whether you can create any code which continues to send location data when the user loads another web-page. The web is a stateless thing and when the user opens another page other code is executed. I suspect that the JSP is the codebase from which HTML is produced when sent to the mobile-phone. My idea would be to add the location sending functionality as AJAX requests in the Javascript. If your web-app is based on many links between pages and full loads it could also be an idea to implement Ajax for loading new content into the page.
Related
I am designing an integration process where my Plone 4 site can share objects and content with other systems when a user decides to publish an object to remote servers. One of the first steps towards making this a reality is adding a "Remote Publish" CMF action off of an ATFolder for instance. I did this in the portal_actions tool provided in the ZMI. I set the URL expression to ${globals_view/getCurrentFolderUrl}/publish.
Now I understand that I need to register the action somewhere to get it to present a form that asks for the remote server address that handles the web service calls. How do I build and send a POST REQUEST with the folder object's new properties and children when the user has clicked the new "Remote Publish" button?
You need to split this problem to subproblems and solve each individually
How to customize Plone
http://developer.plone.org/getstarted/index.html
How to add actions to content items
https://developer.plone.org/functionality/actions.html
How to create a form which asks for a remote server address and where you can program Python logic
http://developer.plone.org/reference_manuals/external/plone.app.dexterity/schema-driven-forms/index.html and https://developer.plone.org/forms/z3c.form.html
How to read folder and object content in Plone
http://developer.plone.org/content/listing.html
http://developer.plone.org/content/archetypes/fields.html#accessing-archetypes-field-value
How to create a POST request in Python
http://docs.python-requests.org/
How to make remote server to handle the incoming request
[not part of the question]
Unless you do not have enough Python and Plone experience this is quite big question to tackle. To solve this problem I suggest you create a new sub-question for every part and solve them independently.
As the title implies,
I need to fetch data from certain website which need logins to use.
The login procedure might need cookies, or sessions.
Do I need QtWebkit, or can I get away with just QNetworkAccessManager?
I have no experience at both, and will start learning as I go.
So please save me a bit of time of comparing both ^^
Thank you in advance,
Evan
Edit: Having read some related answers,
I'll add some clarifications:
The website in concern does not have an API. So I will need to scrape web elements for the data myself.
Can I do that with just QNetworkAccessManager?
No, in most cases you don't need a full simulated web browser. In most cases, just performing the same web requests like a web browser would do is enough.
Try to record the web requests in your browser, using a plugin like "HTTP Live Headers" or "Firebug" in Firefox. I think Chrome provides a similar tool out of the box. These tools record the GET and POST requests done by the website when you send a form in the webpage.
Another option is to inspect the HTML code of the login page. Find the <form> tag and its fields. Put them together in a GET / POST request in your application to simulate the same form.
Remember that some pages use randomized "tokens" in their forms, some set the tokens as cookies. In such cases, you need to request the login page itself in your application first (before sending the filled in form). Both QWebView and QNetworkAccessManager have cookie support.
To sum things up, I think QWebView provides a far more elegant way to simulate user interaction with a web page. The manual way is, however, more "lightweight", as you don't need Webkit and your application might be faster (because only the HTML page is loaded, without any linked resources like images, CSS, javascript files).
QWebView as class name states is a view, so it views something (in this case web pages). If you don't need to display loaded page, then you don't need a view. QNetworkAccessManager may do the work, but you need some knowledge about HTTP protocol, and also anything about target site: how does it hande logins, what type of request you have to send to login etc.
We're developing a tablet app, and my coworker had a rogue thought:
What if you put a manifest attribute on the html tag of a ColdFusion page? Would it
still work if the user couldn't get to the server?
I think it's lunacy, but I wanted to hear what you guys had to say.
The client side is not aware of how is generated the page. He didn't even know if the page is generated. So, the page is cached like another page.
If you are not connected, the could handle this case with some javascript and alert the user you can't communicate with the server.
You could simply disable the application or work with localStorage etc...
I have a test django app.
In one page the test show the same question to all users.
I'd like that when a user answers correctly, send a signal to other active user's browser to refresh to the next question.
I have been learning about signals in django I learning work with them but I don't now how send the "refresh signal" to client browser.
I think that it can do with a javascript code that check if a certain value (actual question) change and if change reload the page but I don't know this language and the information that I find was confused.
Can anybody help me?
Many Thanks.
There is no existing way to send a event from server to browser. But you can get your web page polling your server periodically (say every 5 seconds).
The code in javascript/jquery could be like the following
setInterval(function(){
$.post("your_ajax_handler_url/is_answerd", userId, function(xhr){
if(xhr.responseText == "answered"){
location.reload(true);
}
}
}, 5000);
That is not at all what signals in Django are for. Signals in django are server side hooks that allow you perform tasks on the server when a certain even happens.
To 'send a refresh' to the browser, you need to use a server-push approach such as Comet. Alternatively you can get your clients to periodically poll the server to look for update.
Here's some links:
How to implement Server push / long polling / comet using PHP and Javascript
How do I implement basic "Long Polling"?
What you need are coment(http://en.wikipedia.org/wiki/Comet_%28programming%29) and tornado(http://www.tornadoweb.org/)
I'm trying to distinguish between a web request coming from inside the iframe of my app in facebook vs a regular web visit. That way I can deliver the correct layout.
I had set a session variable when the first iframe request comes into my server (facebook sends a POST param called signed_request to your default canvas url), but then if the user actually visits me website after (outside of facebook) they get iframe layout delivered instead of what my site should look like.
I've looked through all the META info that come in with the iframe request and I dont see anything that would allow me to distinguish the two.
Any help would be much appreciated.
UPDATE: I'm using AppEngine as my application host
The easiest way is to make a unique url for access from Facebook, e.g. if your website is www.site.com then set up either fb.site.com or www.site.com/fb on your server and point it to the same place as www.site.com (and of course set your Facebook app settings to use the alternate url). Then your server code can easily check the accessing url to determine whether to format for Facebook or standalone website.
Another approach is to combine a session variable on the server-side with some javascript on the client-side. You can set a session variable when you receive the signed_request parameter, and then check it on each page load. As long as the session variable is set, you output iframe format and add a bit of javascript code to each page. The javascript checks to make sure the page is still in an iframe using something like if (window.self!=window.top) { //inside iframe }. If not inside an iframe it means the session variable is now stale, so the js jumps to some url that tells the server to clear it and then re-display the page in regular layout.