Java 为什么这句出错了“String s = getParameter(num);”?

来源:百度知道 编辑:UC知道 时间:2024/06/24 13:02:03
import java.applet.Applet;
import java.awt.Graphics;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author stud
*/
public class Java_2 extends Applet {

int num;

public void init() {
//*********Found********
String s = getParameter(num); //从html文件中获取参数
num = Integer.parseInt(s);
}

public void paint(Graphics g) {
for (int i = 0; i < num; i++) {
g.drawString("Hello!", 25 + i * 50, 25);
}
}
}

request.getParameter();
getParameter()这个方法是request中的 你不调用request怎么能使用getParameter()方法呢?
先把java的API看明白吧

你的Java_2类改成servlet类型,并且在默认给你的那个方法里String s = request.getParameter("num");来接收就可以了

String s = request.getParameter("num");