웹 요청으로 전달 받은 숫자 문자열을 수식에 활용하기 위해서는 해당 문자열을 정수로 변환해주어야합니다.
문자열을 정수로 변환하는 메서드 Integer.parseInt() 사용
int number = Integer.parseInt(request.getParameter("number"));
request.getParameter("number")는 웹 요청으로 "number"라는 이름의 매개변수(parameter) 값을 가져옵니다.
이 값은 문자열 형태라, Integer.parseInt()를 사용하여 이 문자열을 정수로 변환합니다.
그 결과로 얻은 정수는 number 변수에 할당됩니다.
반응형
'Java' 카테고리의 다른 글
서블릿(Servlet)과 JSP(JavaServer Page) 비교 (0) | 2024.01.12 |
---|---|
[Java]문자열 일치 조건 .equals("") (0) | 2024.01.11 |
[Java]아이디 또는 비밀번호를 입력하지 않았을 때, 돌려보내는 방법:"null"? (0) | 2024.01.08 |