English 中文(简体)
• 如何从Serlet获得Json物品
原标题:How to get Json object in JSP scriptlet coming from Servlet

I m new to Adobe CQ. I m not even sure how to put this question

我急切地把降幅活下来, drop倒应该叫“共同财产计划”,它将把JSON的回复目标放在文字上,Jsp应当从一个保护工具中拿到Json的物体。

我的格乌斯发言方式如下:

下降人口

<%@ page import="com.day.cq.wcm.api.WCMMode,
                   com.day.cq.wcm.api.components.DropTarget%>

<%
  [
  {key1,value1},
   {key2,value2},
 {key2,value3}

]

%>

因此,我计划使用以下分类:

<script>
$(document).ready(function() {
    $.get( ActionServlet ,function(responseJson) {                          
          alert( response json:  + responseJson);   
    });
});      
</script>

但是,如何以上述形式将这一问题提交菲律宾统计局?

问题回答
$.ajax({

        url : "NameServlet",
        dataType :  json ,
        error : function() {

            alert("Error");
        },
        success : function(data) {
            $.each(data.jsonArray, function(index) {
                var selectBox="<select>"
                  $.each(data.jsonArray[index], function(key, value) {
                    selectBox+="<option>"+key + " & value " + value + "</option>";

                 }); 
                 selectBox+="</select>";
                 // given html id which you want to put it 
                 $("#htmlid").html(selectBox);
            });

        }
});

希望能为你们提供帮助。

你的笑话应该用JSON来印行。

JSP file:

<%
    //obtain the data from a query
    //asuming getClients() return a String in JSON format
    String clients = DB.getClients();

    //this prints de json in the response out
    out.print(clients);
%>

之后,你可以接触含有 j子物体的扼杀。

超文本档案(或另一份联合材料档案):

<script type="text/javascript">
    //url from your JSP page
    //data contains the output printed previously
    $ajax(url,function(data){
        //it is convenient to clean de output
        var stringData = data.trim();

        //now that you have a json formated String you need to use a parser that
        //converts the String into a JsonObject
        var jsonData = JSON.parse(stringData);

        //take some actions with the data obtained
        var htmlVar =   ;
        for (var i=0; i<jsonData.length; i++){
            //add to htmlVar the HTML code for the options 
            htmlVar +=  <option value=" +jsonData[i].clientId+ "> +jsonData[i].clientName+ </option> 
        }
        //load the data into the dropDown element
        $( #clientsDropDown ).html(htmlVar)
    });
</script>




相关问题
Convert typed-in Text to lowercase

I ve got an index.jsp with [snip] <% String name = request.getParameter("name"); String pass = request.getParameter("pass"); String globalname = "webeng"; String globalpass = "2009"; ...

session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

Setting the default value in Struts2

I am setting the value(kind of default value) for a drop down select value from action class in a page(given below). When the page loads the value is beig displayed but the other elements of the ...

Evaluate dynamically constructed JSP at runtime

I have a requirement where in the JSP page itself is created by the user and stored in the database. When viewing results we need to render this JSP to the client, evaluating all tags inside this JSP. ...

How to Pack/Encrypt/Unpack/Decrypt a bunch of files in Java?

I m essentially trying to do the following on a Java/JSP-driven web site: User supplies a password Password is used to build a strongly-encrypted archive file (zip, or anything else) containing a ...

JSP exception - class not found (tomcat)

I m setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root ...

ArrayList to Table in JSP

I have an ArrayList and i am trying to display it in a table ..... ArrayList rows = .... ..... <table cellspacing="1" cellpadding="4" border="3"> <tr> <TH>...

热门标签