Issue
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String category[] = request.getParameterValues("category");
}
String Category[]
line displays:
"The value of the local variable category is not used"
Secondly, I want to pass this array to my controller class to set as its getters/setter:
public class Controller {
private String[] category;
public Controller(String[] category) {
super();
this.category[] = category;
}
}
This throws error:
"Type mismatch: cannot convert from String[] to String"
I am beginner. Please advise how can I fix these two errors/warnings
Best regards
Solution
That is because you are trying to set an array, which is technically a reference object, to another array(another reference object). When you are defining your arrays you will need to have the square brackets but when trying to call on the variable you won't always need it.
this.category[] = category;
needs to become
this.category = category;
This line will give you what you want and define category. I know you said you were a beginner but I'd try looking into ArrayLists because they will make your life a lot easier in things like this.
Answered By - Nick