Double
50
2020-08-01 18:57:34 작성 2020-08-01 18:58:10 수정됨
0
134

Spring 한글깨짐 문제..


네이버 책 검색 api를 따라서 완성했는데 결과에 한글이 깨져서 나오는데 해결이 안되네요..


book.jsp (utf인코딩 관련된거 찾아서 다 넣어봣는데도 깨지네요.)

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

<% response.setContentType("text/html"); %>
<% request.setCharacterEncoding("UTF-8"); %>

<!DOCTYPE HTML>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <div>
        <form action="bookList.do">
            <input type="text" name="keyword" >
            <input type="submit" value="검색">
        </form>
    </div>
    
    <table>
        <tr>
            <td colspan="7" width="100%" bgcolor="pink"></td>
        </tr>
        <c:forEach items="${bookList}" var ="b">
            <tr>
                <td rowspan="2"><img src="${b.image}"></td>
                <td rowspan="4" width="800">"${b.title}"</td>
                <td width="200">${b.author}</td>
            </tr>
            <tr>
                <td width="200">${b.price }</td>
                <td width="200">${b.discount }</td>
                <td width="200">${b.publisher }</td>
                <td width="200">${b.pubdate }</td>
                <td width="200">${b.isbn }</td>
            </tr>
            <tr>
                <td colspan="7">${b.description}</td>
            </tr>
            <tr>
                <td colspan="7" width="100%" bgcolor="pink"></td>
            </tr>
        </c:forEach>
    </table>
</body>
</html>


Contoller 부분

	@Controller
	public class BookController {
	    @Autowired
	    private NaverBookService service; 
	    
	    //키워드가 있을때도 있고 없을때도있음 
	    //있을때는 가져가고 없을때는 안가져가고 
	    @RequestMapping("bookList.do")
	    public ModelAndView bookList(@RequestParam(required=false)String keyword){
	        ModelAndView mav = new ModelAndView();
	        
	        if(keyword !=null)
	        {
	            mav.addObject("bookList",service.searchBook(keyword,10,1));
	        }
	        mav.setViewName("bookList");
	        return mav;
	    }
	}


api연동 부분 URL 인코딩 부분 UTF-8로 설정되있는데도 깨짐..

public List<Book> searchBook(String keyword, int display, int start) {
        URL url;
        List<Book> list = null;
        try {
            url = new URL("https://openapi.naver.com/v1/search/book.xml?query=" + URLEncoder.encode(keyword, "UTF-8")
                    + (display != 0 ? "&display=" + display : "") + (start != 0 ? "&start=" + start : ""));
            URLConnection urlConn;


톰캣server.xml , web.xml 인코딩 다 utf-8로 해봤는데 깨지는 이유좀 알려주세요 ㅜㅜ

0
0
  • 답변 0

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