Apache Tomcat, Servlet, AJAX

来源:互联网 发布:山东博达网络 编辑:程序博客网 时间:2024/05/21 19:22

Apache Tomcat

The Tomcat server does what a regular web server does while also providing an environment for running Servlets, such as JAVA classes, that can receive web requests and generate web responses.


Servlet variables

A servlet is instantiated by Tomcat once at the start of the web application. All incoming requests go to the same servlet. So some variables will take all requests the servlet has received.


Request/Response

The servlet is handed a HttpServletRequest and HttpServletResponse that are used to obtain information about the request and to send back to a response.

Parameters from the request can be accessed; and session information can be accessed.

Session information can be used to identify subsequent requests coming from the same user.

Response can have a variety of types including HTML, XML and JSON. A response may also be a redirection to something else.


AJAX

Asynchronous JavaScript with XML:

HTML or XHTML and CSS for presentation

DOM for dynamic display and interaction with data

XML for interchange of data: not required, could use JavaScript Object Notation (JSON), or simply pre-       formatted HTML or plain text

XSLT(Extensible Stylesheet Language Transformation) for manipulation and display of data: only used if using XML as well

XMLHttpRequest object for asynchronous communication

JavaScript (or VBScript) to combine all of above.

AJAX info

Ajax: A new approach to Web Application

XML Matters: Beyond the DOM

Ajax for Java developers: Build dynamic Java applications

Ajax for Java developers: Java object serialisation for Ajax

Synchronous vs Asynchronous

The classic (non-AJAX) model is synchronised with user activity, while AJAX model decouples user activity.

jQuery and JSON web request

The getJSON call is asynchronous; the callback is called when the valid response is received from the server. Be careful is generating more than one outstanding call at a time. If the response is not valid JSON then the callback will not be called.

JSON at the servlet

The JSON request can be handled in the Servlet as a normal request.

The response is JSON formatted.

Drawbacks to AJAX

harder to develop than static pages

not automatically registered in browser history: there are workarounds such as changing the URL fragment    identifier(after the #)

    makes it difficult to bookmark a state of the application

asynchronous behaviour not obvious to users

not as easy to access for web crawlers

incompatible browsers require fall-back to non-AJAX variation

cross domain access is currently restricted

may significantly increase number of requests to server.