jsp如何调用java类以及类里的数组方法
我的类文件
package javabean;
public class HelloWord {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("你好,JAVA!");
HelloWord.sayOK();
System.out.println(HelloWord.getHello());
int a[]=null;
a = new int[10];
for(int i=0;i<10;i++){
a[i] = 2*i;
System.out.println(a[i]);
}
}
public static void sayOK()
{
System.out.println("OK");
}
public static String getHello()
{
String str1 = "Hello";
return str1;
}
public static String removeHtml(String str) {
String strText = null;
strText = str.replaceAll("<(?:.|\\s)*?>", "");
return strText;
}
public static void ArrayDemo(int array[])
{
int a[]=null;
a = new int[10];
for(int i=0;i<10;i++){
a[i] = 2*i;
System.out.println(a[i]);
}
}
}
jsp页面调用
<%@ page import="javabean.HelloWord"%>
<%
String strText="<font color=red>java</font>";
out.print(HelloWord.removeHtml(strText));
out.print(HelloWord.getHello());
out.print(HelloWord.main());
//out.print(HelloWord.ArrayDemo(int array[]));报错
%>
访问jsp文件可以正常打印。我现在问的是如何正确的打印ArrayDemo()方法,还有如何直接就调用main()方法打印出来。初学者,如有描述不对的地方见谅:)