小编use*_*116的帖子

使用Wicket AbstractAjaxBehavior和jQuery.ajax()

我已经使用jQuery AJax调用来发送JSON,如StackOverflow中所述

问题是我没有收到服务器上的任何数据.我可以看到调用确实达到了目标ajax行为 - 但在onRequest()方法中,RequestCycle dd不包含任何参数

我的Wicket代码:

        AbstractAjaxBehavior ajaxSaveBehaviour = new AbstractAjaxBehavior(){
        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        public void onRequest()
        {
            //get parameters
            final RequestCycle requestCycle = RequestCycle.get();



            final PageParameters pageParameters = new PageParameters(requestCycle.getRequest().getParameterMap());
            logger.info(" I have received something 1");

            for(String pkey: requestCycle.getRequest().getParameterMap().keySet()){
                String[] valArry= requestCycle.getRequest().getParameterMap().get(pkey);
                StringBuffer sb = new StringBuffer();
                for(String s: valArry) sb.append(s).append(" , ");
                logger.info("pk :"+ pkey + " = "+ sb.toString());
            }

            //do something using nice json library to produce a string …
Run Code Online (Sandbox Code Playgroud)

jquery wicket

7
推荐指数
1
解决办法
4895
查看次数

如何将Redis中的排行榜限制为仅限N个元素?

我需要创建一个具有最大元素数量的排行榜,比如N?我知道如何使用LPUSH + LTRIM将列表大小限制为N个元素.如何使用Redis sortedset为排行榜实现此目的

到目前为止,我的方法是分三步完成:a)ZADD将分数+项添加到排行榜

b)找到第N个元素的等级(我不知道该怎么做)

c)执行ZREMRANGEBYRANK排行榜0 rank_of_the_nth_element.

有没有更好的办法 ?

algorithm leaderboard nosql redis

7
推荐指数
1
解决办法
2635
查看次数

如何使用Java反射将值从Java Bean自动复制到Protobuf消息对象?

通常,我可以使用具有Java反射的beanutils在两个具有相同属性名称的java bean之间复制值,例如PropertyUtils.setProperty(....)

在protobuf Message中,我们使用消息构建器类来设置值。这行得通,但是我宁愿使用反射将属性从Bean自动复制到消息中,因为两者具有相同的属性名称和类型。

当我在构建器对象(从message.newBuilder()获得)上调用PropertyUtils.setProperty时,得到此消息。

java.lang.NoSuchMethodException:属性“ testProp”在类“ testsuff.TestBeanProtos $ TestBeanMessage $ Builder”中没有setter方法

如何使用Java反射将值从Java bean自动复制到protobuf消息对象(反之亦然)?

java reflection protocol-buffers

5
推荐指数
1
解决办法
6796
查看次数

如何在 Java HttpURLConnection 中禁用多部分表单发布的缓冲?

(这是一个签名的小程序,我决定不使用 HTTPClient 以保持我的 jar 非常小)

我正在使用 HttpURLConnection 使用多部分表单发布成功将文件从用户上传到服务器。

问题在于 HttpURLConnection 在发送数据之前会缓存数据。因此,当我从文件中读取数据并写入 Outputstream 时,它只是缓冲数据 - 因此显示上传状态的进度条是完全错误的。但请注意,表单邮政代码有效,并且文件确实已正确上传,返回代码为 200。

那么如何确保 HttpURLConnection 不会缓存我发送到服务器的数据?

这是我的来源:

public UploadResponse send(String formPostUrlStr,String fileFieldName,File targetFile, Map<String, String> valuesMap, UploadStatusListener uploadStatusListener) throws Exception{


    String sendStr=getBoundaryMessage(Boundary,  valuesMap, fileFieldName, targetFile.getName(), valuesMap.get("content-type") );//"image/png") ;

    System.out.println(" multi-part start \n "+ sendStr+ " multi-part end \n");

    String lenstr=Long.toString((long)(sendStr.length()*2)+ targetFile.length());
    System.out.println("Content-Length"+ lenstr);
                        //Content-Length

    URL url= new URL(formPostUrlStr);
    long startTime= System.currentTimeMillis();
    HttpURLConnection s3Connection = (HttpURLConnection) url.openConnection();

    System.out.println("opened url to "+ formPostUrlStr +", connection ok ..");
    s3Connection.setRequestProperty("Content-Type", "multipart/form-data; …
Run Code Online (Sandbox Code Playgroud)

java form-post httpurlconnection

5
推荐指数
1
解决办法
2429
查看次数

如何为Clojure Noir Web应用程序构建war文件?

我能够使用这些命令从此网站上的instrcution生成并运行示例Web应用程序

https://github.com/ibdknox/lein-noir

lein new noir my-project-name
lein run
Run Code Online (Sandbox Code Playgroud)

(我在Java 1.7.0_09 Java HotSpot(TM)客户端VM上使用Leiningen 2.0.0-preview10)

启动Web应用程序运行正常,但我想生成war文件,我可以手动部署到我的应用程序服务器(Websphere).

为Noir项目生成war文件需要什么命令或配置Leingen 2?

为了澄清,这个命令"lein new noir webpoc2"使用这个.clj文件生成一个noir项目

(defproject webpoc1 "0.1.0-SNAPSHOT"
            :description "FIXME: write this!"
            :dependencies [[org.clojure/clojure "1.4.0"]
                           [noir "1.3.0-beta3"]]
            :main webpoc1.server)
Run Code Online (Sandbox Code Playgroud)

如果我将Ring添加到cl文件中

:ring {
                   :handler webpoc1.server/handler

}
Run Code Online (Sandbox Code Playgroud)

,并运行lein ring uberwar,我明白了:

Exception in thread "main" java.lang.RuntimeException: No such var: webpoc1.server/handler, compiling:(
/servlet.clj:1)
        at clojure.lang.Compiler.analyze(Compiler.java:6281)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3497)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6457)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5618)
        at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5054)
        at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3674)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6453)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6443)
        at clojure.lang.Compiler.analyze(Compiler.java:6262) …
Run Code Online (Sandbox Code Playgroud)

web-applications clojure leiningen noir

5
推荐指数
1
解决办法
1034
查看次数

如何在Clojure应用程序中使用Spring Beans?

我有很多spring bean可以封装现有的业务逻辑.现在我希望在我的新Clojure Compojure应用程序中重用那些Spring Beans.我该怎么做呢 ?

我正在寻找的是Clojure相当于此

Context context = new ClassPathXmlApplicationContext(....);

MyBean mybean = context.get("mybean", MyBean.class)
Run Code Online (Sandbox Code Playgroud)

有没有Clojure这样做的方式?

java spring clojure

5
推荐指数
2
解决办法
3070
查看次数

Intellij IDEA:如何验证 XML SCHEMA 1

我正在使用 JDK 7 在 IDEA 13.02 中尝试 XML SCHEMA 1.1

这是我从教程中获得的 XML 架构代码。当我在 IntelliJ IDEA 中打开此文件并单击“验证”时,出现以下错误:

cvc-complex-type.2.4.a:发现以元素“openContent”开头的无效内容。'{" http://www.w3.org/2001/XMLSchema ":annotation, " http://www.w3.org/2001/XMLSchema ":simpleContent, " http://www.w3.org 之一/2001/XMLSchema ":complexContent, " http://www.w3.org/2001/XMLSchema ":group, " http://www.w3.org/2001/XMLSchema ":all, " http://www .w3.org/2001/XMLSchema “:选择,” http://www.w3.org/2001/XMLSchema “:序列,” http://www.w3.org/2001/XMLSchema “:属性,” http预计为://www.w3.org/2001/XMLSchema ":attributeGroup, " http://www.w3.org/2001/XMLSchema ":anyAttribute}'。

这是使用 XML Schema 1.1 增强功能的 XSD 文件:

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.books.org"
        xmlns:pub="http://www.books.org"
        elementFormDefault="qualified">

    <complexType name="Publication" abstract="true">
        <openContent mode="interleave">
            <any />
        </openContent>
        <sequence>
            <element name="Title" type="string" />
            <element name="Author" type="string" />
            <element name="Date" …
Run Code Online (Sandbox Code Playgroud)

xml xsd intellij-idea xml-validation

5
推荐指数
1
解决办法
1万
查看次数

clojure代码示例中的这个函数定义是做什么的?

我跟随'Clojure in Action'并且我对此感到困惑:

(defn with-log [function-to-call log-statement ]
      (fn [& args]
          (println log-statement)
          (apply  function-to-call args)))
Run Code Online (Sandbox Code Playgroud)

这是令我困惑的代码段.这是我到目前为止可以破译的内容:

(defn with-log [function-to-call log-statement] ..)定义一个名为"with-log"的函数,该函数接受参数'function-to-call'和'log-statement'以及函数to-to- call是一个作为参数传递给该函数的函数.下一节让我感到困惑:(fn [&args] ....是一个在这里定义的匿名函数吗?'with-log'函数是否返回一个新的函数定义?

(fn [& args]
          (println log-statement)
          (apply  function-to-call args))
Run Code Online (Sandbox Code Playgroud)

所以通过调用(with-log somefunc"my label") - 它是否只是一个新的匿名函数?或者它是否调用匿名函数?

functional-programming clojure higher-order-functions

4
推荐指数
1
解决办法
367
查看次数

在C程序中,是否可以将所有全局变量重置为默认值?

我有一个我需要重用的传统C Linux应用程序.该应用程序使用了许多全局变量.我想重用这个应用程序的main方法并在循环中调用它.我发现当我在循环中调用main方法(重命名为callableMain)时,应用程序行为不一致,因为在上一次迭代中设置的全局变量的值会影响新迭代中的程序流.

我想要做的是在执行新迭代之前将所有全局变量重置为默认值.

例如,原始程序是这样的

OriginalMain.C

#include <stdio.h>

int global = 3; /* This is the global variable. */

void doSomething(){     
         global++; /* Reference to global variable in a function. */    
}    

     // i want to rename this main method to callableMain() and
     // invoke  it in a loop 
     int main(void){    
       if(global==3) {    
       printf(" All  Is Well \n");    

       doSomething() ;  
     }
     else{

       printf(" Noooo\n");  

       doNothing() ;

     }
     return 0;
}
Run Code Online (Sandbox Code Playgroud)

我想改变这个程序如下:

我更改了上面的文件,将main()重命名为callableMain()

我的新主要方法如下:

int main(){  

     for(int i=0;i<20;i++){  

         callableMain();

         // this is …
Run Code Online (Sandbox Code Playgroud)

c global-variables

3
推荐指数
3
解决办法
6650
查看次数

如何获得Lucene模糊搜索结果的匹配条件?

在使用Lucene模糊搜索时,如何获得匹配的模糊项及其偏移量?

    IndexSearcher mem = ....(some standard code)

    QueryParser parser = new QueryParser(Version.LUCENE_30, CONTENT_FIELD, analyzer);

    TopDocs topDocs = mem.search(parser.parse("wuzzy~"), 1);
    // the ~ triggers the fuzzy search as per "Lucene In Action" 
Run Code Online (Sandbox Code Playgroud)

模糊搜索工作正常.如果文档包含术语"模糊"或"luzzy",则匹配.如何获得匹配的术语以及它们的偏移量是多少?

我确保所有CONTENT_FIELD都添加了termVectorStored和位置和偏移量.

java lucene fuzzy-search

3
推荐指数
1
解决办法
4513
查看次数