小编mes*_*azs的帖子

如何使用js-ctypes Firefox扩展调用本机C代码?

我正在尝试构建一个需要调用本机C代码的Firefox扩展.

我的C程序代码是:

#include<windows.h>
int add(int a, int b)
{
    return(a + b);
}
Run Code Online (Sandbox Code Playgroud)

我的JavaScript代码是:

var {Cu} = require('chrome');
var self  = require('sdk/self');
Cu.import("resource://gre/modules/ctypes.jsm");
var lib;
var puts;
lib = ctypes.open('G:\\Shankar\\Project\\Maidsafe\\Firefox\\addon-sdk-1.17\\jsctype_sample\\data\\Win32Project1.dll');

try {
    puts = lib.declare("add", /* function name */
        ctypes.default_abi, /* call ABI */
        ctypes.int32_t, /* return type */
        ctypes.int32_t, /* argument type */
        ctypes.int32_t /* argument type */
    );
} catch (e) {
    console.log('Érror'+ e);
}

function binaryFile() {        
    var ret = puts(1, 2);
    dump(ret);
    lib.close();
};

exports.binaryFile = …
Run Code Online (Sandbox Code Playgroud)

javascript c firefox-addon jsctypes

9
推荐指数
2
解决办法
1735
查看次数

如何检查数据库中的删除是否成功?

当用户在删除字段中输入错误的ID时,我想要弹出一个错误.但即使输入了错误的ID,查询仍会继续,但不会删除任何数据.这是我的代码:

String value = jTextField19.getText();

if (value == null || "".equals(value)) {
    JOptionPane.showMessageDialog(null, "The field is blank!");
} else {
    theQuery("DELETE FROM inventorydb WHERE item_id=('"+jTextField19.getText()+"') AND item_id IS NOT NULL");
}
Run Code Online (Sandbox Code Playgroud)

theQuery方法:

private void theQuery(String query) {
    Connection con = null;
    Statement st = null;
    try {
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/inventory", "root", "");
        st = con.createStatement();
        st.executeUpdate(query);
        JOptionPane.showMessageDialog(null, "Done!");
    } catch (Exception ex) { 
        JOptionPane.showMessageDialog(null,"Error!");
    } 
}
Run Code Online (Sandbox Code Playgroud)

java mysql

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

HTML标记的位置无效

我正在尝试使用HTML和Servlet创建一个简单的表单.一切都已设定,但我的HTML标记中有一个黄色下划线.它说:标签(输入)的位置无效,我试图在我的HTML中实现表单.

我的代码看起来很好,我没有看到问题.我究竟做错了什么?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    <title>Projektuppgift1</title>
</head>
<body>
    ...
    // This is where I am getting the error
    <form action="LoginServlet" method="post">
        username: <input type="text" name="name" />
        password: <input type="password" name="password" />
        <input type="submit" value="submit" />
    </form>
    ...
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript java

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

隐式、显式和 fluentwait 之间的差异

之间有什么具体区别implicitwait()explicitwait()fluentwait()?你能用例子解释一下吗?

selenium synchronization

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

我如何使用Joiner,仅加入特定属性?

假设我有这个课程:

public class MyClass {
    private String propertyOne;
    private String propertyTwo;
    // getters setters...
}
Run Code Online (Sandbox Code Playgroud)

现在,在我的测试方法中,我尝试的是:

List<MyClass> myList = myListDao.findAll(); 
String aStringFullOfPropertyOnesOfAllMyObjects =  Joiner.on(", ").join(myList.iterator());
Run Code Online (Sandbox Code Playgroud)

String,我希望得到的回复是这样的:

"propOneOfObjectOne, propOneOfObjectTwo, propOneOfObjectThree"
Run Code Online (Sandbox Code Playgroud)

How can I do this?

java guava joiner

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

更新/删除查询不能键入JPA

我正在使用Spring框架来开展培训项目.我也在使用JPA,并且一直有一段时间.在我的DAO实现课中,我写道:

@Override
public void deleteEntries(Module mod) {
    System.out.println(mod.getDescription());
    entityManager.createQuery("delete from TrainingEntry e where e.module = :mod and e.completedDate IS NULL",
                              TrainingEntry.class).setParameter("mod", mod);

}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,它只是一个简单的DELETE语句,但我收到错误:

"Update/delete queries cannot be typed."
Run Code Online (Sandbox Code Playgroud)

我的猜测是,我需要使用一些EntityManager类方法来完成这项工作,但我不确定,因为在线这个错误几乎没有.我也很难应用我在网上找到的有关JPA删除查询的一些解决方案.任何关于正确方向的点或解释为什么抛出这个错误都非常感激.

java spring jpa entitymanager sql-delete

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

在sql中设置参数,查询无效

我在这里有这个代码:

DECLARE @inputform varchar
SET @inputform = 'J61807017B'

SELECT * FROM test where text1 LIKE '@inputform'
Run Code Online (Sandbox Code Playgroud)

这不会给我想要的输出,但是当我这样做时它起作用:

DECLARE @inputform varchar
SET @inputform = 'J61807017B'

SELECT * FROM test where text1 LIKE 'J61807017B'
Run Code Online (Sandbox Code Playgroud)

任何的想法?

sql t-sql

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

与Grizzly一起运行泽西岛

我试图将泽西与Grizzly一起用作自托管

基本上我的主要是:

org.glassfish.jersey.server.ResourceConfig rc = new ResourceConfig();
rc.registerClasses(DummyController.class);
webServer = GrizzlyHttpServerFactory.createHttpServer(uri, rc, false);
System.out.println("Server Created");
try {
    webServer.start();
    System.out.println("Server Started");
} catch (IOException e) {
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个小型控制器:

@Path("/")
public class DummyController {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String get() {
        return "Got it!";
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我运行它时,我得到一个例外:

Exception in thread "main" java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:309)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:289)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:331)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:141)
at RestServer.Server.main(Server.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Run Code Online (Sandbox Code Playgroud)

当我没有添加资源时,灰熊服务器运行正常,但我无法访问任何控制器

我使用Maven下载所有依赖项

这是pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" …
Run Code Online (Sandbox Code Playgroud)

java grizzly jersey-2.0

2
推荐指数
1
解决办法
2407
查看次数

忽略对静态变量的赋值

我有以下代码:

#include <stdio.h>

int f1()
{
    static int s=10;
    printf("s=%d\n",s++);
}
int main()
{
    f1();
    f1();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出是:

s=10
s=11
Run Code Online (Sandbox Code Playgroud)

为什么static int s=10第二次忽略该行,何时f1被调用?

c linux static-variables

1
推荐指数
2
解决办法
1205
查看次数

在新标签中以可读格式显示json

我正在尝试在新窗口中以可读格式显示json。我有一个按钮,当您单击一个新选项卡时,其中会显示json。但是,在新窗口中,json仍未格式化,显示为纯文本。在中console.log,但是格式正确。我不明白为什么会有所不同。

$('.showRawJson').click(function () {
    $.getJSON('somelink', function (json) {
        var myjson = JSON.stringify(json, null, 2);
        // In the console the json is well formatted
        console.log(myjson);
        var x = window.open();
        x.document.open();
        // Here in the new tab the json is NOT formatted
        x.document.write(myjson);
        x.document.close();
    });
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery json

0
推荐指数
1
解决办法
2693
查看次数

在文本文件中插入400个数字

我试图在文本文件中写入1到400之间的数字.我正在使用下面的代码,它运行没有任何错误,但文件是空的.

任何帮助,将不胜感激.

#include <stdio.h>

int main(void)
{
    FILE *filePointer;
    filePointer = fopen("file.txt","w");
    int i; 
    for(i=0; i > 400; i++)
    {
        fputs("%d, ",i,filePointer);
    }
    fclose(filePointer);
    return(0);
}
Run Code Online (Sandbox Code Playgroud)

c text file fputs

0
推荐指数
1
解决办法
90
查看次数