小编Wil*_*ill的帖子

Groovy安装

我试图在Windows 7中安装groovy.我从groovy网站下载了存档.解压缩它.添加GROOVY_HOME环境路径.将bin路径添加到环境中.之后我重新启动了Windows.但是当我尝试从cmd运行groovy时,我得到错误:

错误:无法找到或加载主类org.codehaus.groovy.tools.GroovyStarter

groovy

7
推荐指数
3
解决办法
2万
查看次数

如何从jQuery的$ .ajax()函数调用servlet

我试图从jQuery的.ajax()函数调用一个servlet.

目前我不认为我甚至不会调用servlet或将paramaters传递给它,但是很多Google搜索似乎没有帮助.有任何想法吗?

这是我的HTML:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function login(){  

  $("#loading").hide();

  var email = document.nameForm.email.value;  
  $.ajax({  
    type: "GET",  
    url: "ProcessForm",  
    data: "email="+email,  
    success: function(result){  
      alert(result);
    }                
  });  
}        
</script>
<title>My AJAX</title>
</head>
<body>
<p>This time it's gonna work</p>
<form name="nameForm" id="nameForm" method="post" action="javascript:login()">
Run Code Online (Sandbox Code Playgroud)

电邮加载

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

还有我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>ajaxtry</display-name>
  <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
<servlet-name>ProcessForm</servlet-name>
<servlet-class>com.ajaxtry.web.ProcesFormServlet</servlet-class>
  </servlet>
   <servlet-mapping>
<servlet-name>ProcessForm</servlet-name>
<url-pattern>/ProcessForm</url-pattern> …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery post servlets

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

当我的代码中没有实例化Java类时,是否可以使用Groovy覆盖Java类中的方法?

我正在开发Eclipse RCP应用程序,最近我开始在其中使用Groovy.所以99%的代码仍然是Java.

我读到可以使用Groovy覆盖并向Java类添加方法,我可以通过向java.lang.String添加一个方法来测试它.

但这仅在我在Groovy类中使用字符串时才有效.重写的方法不被视为在Java类中被重写.

这是一些代码:

/*
 * This is a Java class
 */
public class CTabItem {
   ...
   private API
   ...
   public void setControl(Control control){
       private API
   }
}

/*
 * This is also a Java class
 */
public class Control {
   ...
   private API
   ...
}

/*
 * This is also a Java class
 */
public class OtherClass {
  ...
  private API
  ...
  private void someMethodIDontKnow(){
     Control control = new Control();
     CTabItem tab = new CTabItem();
     tab.setControl(control);
  }
} …
Run Code Online (Sandbox Code Playgroud)

java eclipse groovy rcp eclipse-rcp

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

Groovy无法连接到postgresql数据库?

我正在使用Ready API 1.4.0,我尝试使用这个groovy代码连接到postgresql.

import groovy.sql.Sql
import java.sql.Driver

def driver = Class.forName('org.postgresql.Driver').newInstance() as Driver 

def props = new Properties()
props.setProperty("DB_user", "user") 
props.setProperty("DB_password", "user")

def conn = driver.connect("jdbc:postgresql://localhost:54320/database_name", props) 
def sql = new Sql(conn)

try {
    sql.eachRow("select * from user") {
        log.debug(it)
    }
} finally {
    sql.close()
    conn.close()
}
Run Code Online (Sandbox Code Playgroud)

然后我收到了这个错误:

java.lang.ClassNotFoundException:org.postgresql.Driver at line:4

我在bin/ext postgresql-9.4-1205.jdbc42.jar中添加了这个jar lib

有什么帮助吗?谢谢.

postgresql groovy

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

使用闭包在对象上调用一组方法

我有一个叫做的课Test,我有以下代码

def test = new Test()
test.method1(args)
test.method2(args)
Run Code Online (Sandbox Code Playgroud)

等等.我希望可以做到这样的事情,我可以test在闭包中传递对象的所有方法调用并使它们工作.喜欢

test {
    method1(args)
    method2(args)
}
Run Code Online (Sandbox Code Playgroud)

是否可以在groovy中这样做?

groovy

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

Future将从执行程序服务提交返回null

在执行Java到Groovy代码迁移的初始阶段时,我遇到了一个问题,即Groovy版本从Future返回null,而Java返回正确的整数(123).

J1.java和G1.groovy之间唯一的变化是类名和lambda到闭包转换.

//文件:J1.java

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class J1 {
  public static void main (String... args) throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool (1);
    Future<Integer> future = executor.submit (() -> 123);
    System.out.println ("Result: " + future.get ());
    executor.shutdown ();
  }
}
Run Code Online (Sandbox Code Playgroud)

//文件:G1.groovy

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class G1 {
  public static void main (String... args) throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool (1);
    Future<Integer> future = executor.submit ({ -> 123 });
    System.out.println ("Result: " …
Run Code Online (Sandbox Code Playgroud)

groovy

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

标签 统计

groovy ×5

ajax ×1

eclipse ×1

eclipse-rcp ×1

java ×1

javascript ×1

jquery ×1

post ×1

postgresql ×1

rcp ×1

servlets ×1