import java.util.Arrays
import java.util.LinkedList
public class Guy
{
public static void recursionSub ( LinkedList<int[]> list, int count, int[] array, int ind, int start, int... indexs )
{
start++
if (start > count - 1)
{
return
}
if (start == 0)
{
indexs = new int[array.length]
}
for ( indexs[start] = ind indexs[start] < array.length indexs[start]++ )
{
recursionSub (list, count, array, indexs[start] + 1, start, indexs)
if (start == count - 1)
{
int[] temp = new int[count]
for ( int i = count - 1 i >= 0 i-- )
{
temp[start - i] = array[indexs[start - i]]
}
list.add (temp)
}
}
}
public static void main ( String[] args )
{
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }
LinkedList<int[]> list = new LinkedList<int[]> ()
recursionSub (list, 3, array, 0, -1)
for ( int[] strings : list )
{
System.out.println (Arrays.toString (strings))
}
}
}
用ajax的方法.首先将要调用的类名和方法名作为参数传给某个servlet.这一步的方法有许多种,用框架,或者直接用xmlHttpRequest对象.
另外,要调用的类名和类的完整包路径最好写在配置文件里
这里假设类名为Hello,方法名为sayHello,并且sayHello方法不带参数,类路径为com.demo.Hello
配置文件AjaxConfig.properties
Hello = com.demo.Hello
于是传入的参数为 class=Hello&method=sayHello
在servlet中作如下处理:
String className=request.getParameter("classname")
String methodName=request.getParameter("method")
String classPath=null
.
读取配置文件,取出className所对应的值放入classPath变量中(这一步方法有很多种,怎么读配置文件,可以网上找资料,很多的,我就不细写了)
.
Class c=Class.forName(classPath)//加载你所指定的类
Class param[]=new Class[0]//方法的参数为0个
Method m=null
String returnValue=null//返回值
try {
m = c.getMethod("sayHello",param)//获取你所指定的类中的指定方法
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace()
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
try {
returnValue=(String)m.invoke(c.newInstance(), new Object[0])//调用你所指定的方法
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace()
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace()
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace()
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
最后,将returnValue的值返回给客户端即可
类Hello.java
public class Hello
{
public String sayHello()
{
return "hello"
}
}
不明白的加67919823,我们一起讨论呀
有进行编码吗??必须先编码才能解码
编码:encodeURI(str)
解码:URLDecoder d = new URLDecoder()d.decode(str,"utf-8")