상세 컨텐츠

본문 제목

게시글 작성 후 새로고침하면 계속 같은 게시글이 생성되는 에러

트러블슈팅

by ksjsjsj 2024. 5. 10. 17:45

본문

try {

if(description != null && title != null && boardTypeSeq != null &&

!(description.isEmpty() && title.isEmpty() && boardTypeSeq.isEmpty())) {

service.getInsert(params);

}

} catch (NullPointerException e) {

System.out.println("글작성에러");

}

return mv;

}

 

기존 코드에서는 Insert 이후 아무런 조치가 없음

 

>>> 이전에 전송된 폼 데이터가 계속 남아있기 때문에 에러 발생

try {

if(description != null && title != null && boardTypeSeq != null &&

!(description.isEmpty() && title.isEmpty() && boardTypeSeq.isEmpty())) {

service.getInsert(params);

return new ModelAndView("redirect:/forum/notice/listPage.do");

}

} catch (NullPointerException e) {

System.out.println("글작성에러");

}

return mv;

}

 

 

개선된 코드에서는 리다이렉트를 해줌으로써 이전에 전송된 데이터가 남아있지 않

관련글 더보기