[Servlet] MIME νƒ€μž…

μ†Œμ΄λŽΒ·2023λ…„ 11μ›” 28일
1

Servlet

λͺ©λ‘ 보기
5/13
post-thumbnail

πŸ“ MIME νƒ€μž…

  • MIME(Multipurpose Internet Mail Extensions) νƒ€μž…μ€ μΈν„°λ„·μ—μ„œ λ‹€μ–‘ν•œ μ’…λ₯˜μ˜ 데이터λ₯Ό ν‘œν˜„ν•˜κ³  μ „μ†‘ν•˜κΈ° μœ„ν•œ ν‘œμ€€ μ‹λ³„μžμ΄λ‹€.
  • μ„œλ²„κ°€ ν΄λΌμ΄μ–ΈνŠΈμ—κ²Œ μ „μ†‘λ˜λŠ” λ°μ΄ν„°μ˜ μ’…λ₯˜λ₯Ό λͺ…μ‹œμ μœΌλ‘œ μ§€μ •ν•˜μ—¬, ν΄λΌμ΄μ–ΈνŠΈκ°€ μ˜¬λ°”λ₯΄κ²Œ ν•΄μ„ν•˜κ³  ν‘œμ‹œν•˜λ„λ‘ 도움을 μ€€λ‹€.(HTTP ν—€λ”μ˜ Content-Type)
  • Primary Type(μ£Ό νƒ€μž…)/Subtype(λΆ€ νƒ€μž…) ν˜•μ‹μœΌλ‘œ 이루어져 μžˆλ‹€.

πŸ“ μ’…λ₯˜

Primary Type

  • application
  • audio
  • font
  • example
  • image
  • message
  • model
  • multipart
  • text
  • video

1) application

  • json

    // 🟒 src/main/java/com/test/lesson01/UrlMappingEx01.java
    
    package com.test.lesson01;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class UrlMappingEx01 extends HttpServlet {
    
    	@Override
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    		response.setContentType("application/json"); // ⭐️
    		response.setCharacterEncoding("utf-8");
    		
    		PrintWriter out = response.getWriter();
    		out.print("{\"key1\":\"value1\", \"key2\":\"value2\"}");
    	}
    }

9) text

  • plain

    // 🟒 src/main/java/com/test/lesson01/UrlMappingEx01.java
    
    package com.test.lesson01;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class UrlMappingEx01 extends HttpServlet {
    
    	@Override
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    		response.setContentType("text/plain"); // ⭐️
    		response.setCharacterEncoding("utf-8");
    		
    		PrintWriter out = response.getWriter();
    		out.print("<html><head><title>MIME νƒ€μž…</title></head><body>");
    		out.print("<h1>데이터λ₯Ό text/html둜 해석</h1>");
    		out.print("</body></html>");
    	}
    }

  • html

    // 🟒 src/main/java/com/test/lesson01/UrlMappingEx01.java
    
    package com.test.lesson01;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class UrlMappingEx01 extends HttpServlet {
    
    	@Override
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    		response.setContentType("text/html"); // ⭐️
    		response.setCharacterEncoding("utf-8");
    		
    		PrintWriter out = response.getWriter();
    		out.print("<html><head><title>MIME νƒ€μž…</title></head><body>");
    		out.print("<h1>데이터λ₯Ό text/html둜 해석</h1>");
    		out.print("</body></html>");
    	}
    }

References

πŸ”— https://www.iana.org/assignments/media-types/media-types.xhtml

0개의 λŒ“κΈ€