English 中文(简体)
AJAX with Java:HttpServletResponse Affected?
原标题:AJAX with Java: How is HttpServletResponse Affected?

我正在同时学习美国宇宙航空研究开发机构与Java Servlet AP(韦尔,春天),后者是based on Servlets),我认为我理解大多数基本内容,但了解的情况除外。 HttpServletResponse 当服务器/Servlet正在对做出反应时,其结构/组织/人口不同。 HTTP GET/POST(根据正常页数要求),而不是AJRP的“代码”。 XmlHttpRequest。

在我看来,在日本宇宙航空研究开发机构缺席的情况下,每架HttpServletResponse将只包含该网页的全超文本(加头盔/metadat/etc. info)。 与日本宇宙航空研究开发机构一道,可在特定网页上更新components。 因此,如果我正确理解《吉大港山区行动计划》和《服务手册》,请设

<html>
    <header><title>Title of the page</title></header>
    <body>
        <!-- Some massive amount of HTML -->

        <a href="./foo.html">This is a link</a>

        <!-- Lots more HTML -->
    </body>
</html>

而根据日本宇宙航空研究开发机构的请求,HttpServletRequest可能退回信息,以便(从上述例子)现在能够做到这一点:

<a href="./bar.html">This is a new link that point to bar</a>

我的问题是: Java Servlets如何构筑HttpServletRequests,处理整页要求,以及AJAX的要求,这些要求可能只产生页数的改动?

客户(浏览器)如何知道采用<代码>是一个类似的问题。 HTTP Responses (sent Back by the Servlet) and or make a whole new page or only Update a small part of a page.

事先对此问题的澄清表示感谢。

最佳回答

I am understanding most of the basics, except when it comes to understanding how HttpServletResponse is structured/organized/populated differently when the server/Servlet is responding to an HTTP GET/POST (as it would with a normal page request) as opposed to an AJAX-based XmlHttpRequest.

I think your confusion is rooted in thinking about AJAX requests and non-AJAX requests as being fundamentally different. First of all, it is important to know what AJAX is. From wikipedia:

Despite the name, the use of XML is not needed (JSON is often used instead), and the requests do not need to be asynchronous.

我还要补充指出,除 Java本外,其他一些描述文字的浏览器可以使用。 因此,这个名字绝对没有告诉你。 “美国宇宙航空研究开发机构”基本上只是说,从浏览器的文字中删除了吉大港群岛的请求,而不是像地址中打着卢爱阵的人提出的申请。

因此,提出吉卜赛人的申请的描述法可以选择处理服务器发送或可以忽略的任何吉卜赛人协会的答复。 请求的产生方式——“AJAX”或非“AJAX”——不必对所交回的吉大港定居地安置点的反应有任何影响。

问题回答

Ajax要求(基本上)在服务器方面并不不同:回报由URL、参数、内容类型等决定。 任何组合均可用来确定哪些数据被退回。

客户的Ajax要求(通常是)由网络评估员具体提出。 因此,答复者将知道如何处理所返还的数据,是否是超文本(如上所示)、JSON、XML等。

我完全认为,你所需要的不是你如何回答你的问题,而是你如何响应贾克斯的请求,最简单的办法是通过JSON、XML或简单地处理它,把你的职责联系起来。

In case you have defined an id tag for your <a>, something like

 <html>
     <body>
          <a href="" id="myLink">click here!</a>
     </body>
 </html>

then on your callback function (the onreadystatechange function of the XMLHTTPRequest object) you should do something like this:

retreq.onreadystatechange=function ()
    if (retreq.readyState==4){
        if(retreq.status==200){
             if(document.getElementById(idelemento)!=null){
                  document.getElementById("myLink").href=retreq.responseText;
             }
        }
    }   
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签