局部变量类别的值没有被使用
The value of the local variable category is not used
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String category[] = request.getParameterValues("category");
}
String Category[]
行显示:
"The value of the local variable category is not used"
其次,我想将此数组传递给我的控制器 class 以设置为它的 getters/setter:
public class Controller {
private String[] category;
public Controller(String[] category) {
super();
this.category[] = category;
}
}
这引发错误:
"Type mismatch: cannot convert from String[] to String"
我是初学者。请告知如何解决这两个 errors/warnings
此致
那是因为您试图将一个数组(从技术上讲是一个引用对象)设置为另一个数组(另一个引用对象)。当你定义你的数组时,你需要方括号,但当你试图调用变量时,你并不总是需要它。
this.category[] = category;
需要成为
this.category = category;
这一行会给你你想要的并定义类别。我知道你说你是初学者,但我会尝试研究 ArrayLists,因为它们会让你的生活更轻松。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String category[] = request.getParameterValues("category");
}
String Category[]
行显示:
"The value of the local variable category is not used"
其次,我想将此数组传递给我的控制器 class 以设置为它的 getters/setter:
public class Controller {
private String[] category;
public Controller(String[] category) {
super();
this.category[] = category;
}
}
这引发错误:
"Type mismatch: cannot convert from String[] to String"
我是初学者。请告知如何解决这两个 errors/warnings
此致
那是因为您试图将一个数组(从技术上讲是一个引用对象)设置为另一个数组(另一个引用对象)。当你定义你的数组时,你需要方括号,但当你试图调用变量时,你并不总是需要它。
this.category[] = category;
需要成为
this.category = category;
这一行会给你你想要的并定义类别。我知道你说你是初学者,但我会尝试研究 ArrayLists,因为它们会让你的生活更轻松。