2개의 JSP를 하나의 서블릿으로 돌리기 위해 서블릿에 파라미터 값을 요청하고
해당 값이 없을 때는 A를 실행, 값이 있을 때는 B를 실행시키도록 프로그램을 짰다.
난 당연히 넘어오는 값이 없을 때는 petbno에 0이 저장될 줄 알았으나,
int petbno = Integer.parseInt(request.getParameter("petbno"));
결과는 계속 nullpoint 에러가 떴다.
문제는 서블릿에서 넘어올 값이 없으면 아예 getParameter 지점에서 에러를 띄어버린다.
그래서 getParameter를 if문 내로 집어넣으니 정상적으로 작동됐다..
int bno = Integer.parseInt(request.getParameter("bno"));
String status = request.getParameter("status");
String entercheck = request.getParameter("entercheck");
String nowStatus = null;
if(entercheck.equals("1")) {
EnterDAO dao = new EnterDAO();
nowStatus = dao.statusChange(bno, status);
}else {
int petbno = Integer.parseInt(request.getParameter("petbno")); //요녀석!
AdoptDAO dao = new AdoptDAO();
nowStatus = dao.statusChange(bno, status, petbno);
}
response.setContentType("application/x-json; charset=utf-8");
PrintWriter out = response.getWriter();
out.print(nowStatus);
'JAVA' 카테고리의 다른 글
spring boot 프로젝트 전 개념정리 (0) | 2022.08.29 |
---|---|
List<Map> (0) | 2022.08.04 |
[Java] Map, HashMap, LinkedHashMap (0) | 2022.08.04 |
null과 ""를 구분해서 쓰자.. (0) | 2022.05.18 |
로그인 알고리즘 (0) | 2022.05.18 |