너무어려웡
502
2017-05-13 15:41:11 작성 2017-05-13 15:42:42 수정됨
3
659

ajax 관련 오류 질문입니다 ㅠ


spring 이용해서 게시판 만들고 있는데요..

댓글 삭제 기능 하려고 하는데요

-controller-


@Controller
public class CommentController {
	
	public static final String VIEW_PATH="/WEB-INF/views/comment/";
	
	CommentDao dao;
	
	@Autowired
	HttpServletRequest request;
	
	@Autowired
	HttpSession session;
	
	public CommentController() {
		// TODO Auto-generated constructor stub
	}

	public CommentController(CommentDao dao) {
		super();
		this.dao = dao;
	}

	@RequestMapping("/comment_list.do")
	public String comment_list(){
		int b_idx = Integer.parseInt(request.getParameter("b_idx"));
		List<CommentVo> list 
			 = dao.selectList(b_idx);
				
		request.setAttribute("list", list);
		return VIEW_PATH+"comment_list.jsp";
	}

	@RequestMapping("/comment_delete.do")
	public String comment_delete(CommentVo vo){
		System.out.println(request.getParameter("b_idx"));
		int b_idx = Integer.parseInt(request.getParameter("b_idx"));
		int res = dao.delete(vo.getC_idx());
		List<CommentVo> list = dao.selectList(b_idx);
		
		request.setAttribute("list", list);
		return VIEW_PATH + "comment_list.jsp";
	}


-board_view.jsp-

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<script type="text/javascript" src="${ pageContext.request.contextPath }/resources/js/httpRequest.js"></script>
<script>
	window.onload=function()
	{
		load_comment();
	};
	
	function load_comment()
	{
		var url = "comment_list.do";
		var param="b_idx=${ param.b_idx }";
		sendRequest(url, param, resultFn, "GET");
	}
	
	function resultFn()
	{
		if(xhr.readyState==4 && xhr.status==200)
		{
			//요청에 따른 결과를 수신(Ajax)
			var data = xhr.responseText;
			//alert(data);
			//수신결과를 댓글영역에 출력
			document.getElementById("disp").innerHTML = data;
		}
	}
	
	function comment_delete(f){
		var c_idx=f.c_idx.value;
		var url = "comment_delete.do";
		var param =  "b_idx=${param.b_idx}&c_idx="+c_idx;
		sendRequest(url, param, resultFn, "GET");
	}
	
</script>
</head>
<body>

<table>
	<tr>
		<td> <div id="disp"></div> </td>
	</tr>
</table>
			 
</body>
</html>

-comment_list.jsp-

<c:forEach var="vo"  items="${ list }">
	<form>
   <input id="c_idx" type="hidden" value="${vo.c_idx}">
   <table>
	   <tr>
	   	<td>${ vo.nick }</td>
	   	<td> ${ vo.comment_content }</td>
	   	<td><button onclick="comment_delete(this.form);">삭제</button></td>
	   </tr>
   </table>
   </form>
</c:forEach>


소스는 대략 이런데요..

삭제 버튼을 누르면

url : http://localhost:9090/atct/board_view.do? 에

HTTP Status 500 - Request processing failed; nested exception is java.lang.NumberFormatException: null

type Exception report

message Request processing failed; nested exception is java.lang.NumberFormatException: null

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NumberFormatException: null
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

root cause

java.lang.NumberFormatException: null
	java.lang.Integer.parseInt(Integer.java:542)
	java.lang.Integer.parseInt(Integer.java:615)
	com.ic.atct.BoardController.board_view(BoardController.java:214)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke(Method.java:498)
	org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

note The full stack trace of the root cause is available in the Apache Tomcat/8.0.36 logs.


Apache Tomcat/8.0.36


뜨더라구요...

댓글 입력 같은 경우에는 잘 되는데... 

같은 패턴으로 삭제도 해준건데 왜 이러는지 모르겠네요 ㅠㅠ

db 확인해보면 지워지기는 했는데 뭐가 문제일까요ㅠㅠ?

0
0
  • 답변 3

  • kenu
    47k
    2017-05-13 16:30:05
    java.lang.NumberFormatException: null
    	java.lang.Integer.parseInt(Integer.java:542)
    	java.lang.Integer.parseInt(Integer.java:615)
    	com.ic.atct.BoardController.board_view(BoardController.java:214)
    0
  • 너무어려웡
    502
    2017-05-13 16:36:42

    comment_list.jsp에 

    <input id="b_idx" name="b_idx" type="hidden" value="${vo.b_idx}">

    소스 추가 해주니깐 해결 되기는 했는데...

    스크립트에서는 파라미터에 있는 b_idx로 넘기려고 했던건데 어떻게 된걸까요..?

    0
  •  (づ。◕ ܫ ◕。)づ
    4k
    2017-05-13 16:47:04

    jsp와 서블릿에 대한 개념이 필요해요

    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.