Issue
I am trying to pass studentId of datatype int to servlet but it does not accept it and forces to change the datatype to String
int studentId;
String studentName;
studentId = request.getParameter("StudentId"); // (cannot convert from int to String).
I can't change it to String as in the database studentId is an integer (primary key) and my java class also takes an int as a parameter.
How can I solve this?
Solution
you need to parse the parameter as an int. In a request the parameters are just strings at the end of the day (they were typed into a browser, or stored in the html of a webpage after all), so you need to interpret it on the server as the type you expect.
studentId = Integer.parseInt(request.getParameter("StudentId"));
Answered By - Sam Holder
Answer Checked By - Marie Seifert (JavaFixing Admin)