728x90
ํ๋ก์ ํธ ๋ด๋ถ์ ์๋ ํด๋๋ก ์ ๊ทผํ์ฌ ์ด๋ฏธ์ง ํ์ผ์ ๊ฐ์ ธ์ฌ ๊ฒฝ์ฐ ์ฃผ์ํ ์
<img src="/images/ํด๋๋ช
/img์ด๋ฆ.jpg'" style="width:400px;height:400px;vertical-align:middle;"/>
์ฌ๋ฌ ์ด๋ฏธ์ง(ํ์ผ)๋ฅผ ํ๋ก์ ํธ ๋ด๋ถ์ ์ถ๊ฐ ํ ํ๋ก์ ํธ๋ฅผ ๋น๋ํ๊ฒ ๋๋ฉด ์ฉ๋์ด ์ปค ๋น๋ ์๊ฐ์ด ๋๋ ค์ง๊ณ ,
Git์ด๋ SVN์ push์ ์ ํ์ด ์์ ์ ์๋ค.
๊ทธ๋์ ์ด ๋ฐฉ๋ฒ๋ณด๋จ ํ๋ก์ ํธ ์ธ๋ถ์ ์๋ ํด๋๋ก ์ ๊ทผํ์ฌ ์ฌ์ฉํ๋ ๊ฒ ์ ์ถ์ฒํ๋ค.
* ํ๋ก์ ํธ ์ธ๋ถ์ ์๋ ํด๋๋ก ์ ๊ทผํ์ฌ ์ด๋ฏธ์ง ํ์ผ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ *
Globals.dir=/home/WEB_FILE/FILES/
globals.properties๋ฅผ ํตํด์ ํ๋ก์ ํธ ๋ฐ์ ์๋ ๊ฒฝ๋ก๋ฅผ ์ค์
/home/WEB_FILE/FILES/์ ์ด๋ฏธ์ง๋ค์ด ์์ด์ผ ํ๋ค.
js
<img src="/common/getImg.do?fileNM='+item.fileNM+'"style="width:400px;height:400px;vertical-align:middle;"/>
controller
@RequestMapping(value="/common/getImg.do" , method=RequestMethod.GET)
public void getImg(
@RequestParam(value="fileNM") String fileNM,
HttpServletResponse response) throws Exception{
String DIR = globalProperties.getProperty("Globals.dir");
String filePath = DIR+fileNM;
getImage(filePath,response);
}
์ธ๋ถ ์ค์ ํ์ผ(globalProperties)์์ ์ง์ ํ key๊ฐ(Globals.mgeoDir)์ ๋ถ๋ฌ์ค๋ฉด DIR ๋ณ์์ ํด๋น ๊ฒฝ๋ก ๊ฐ์ด ๋ฆฌํด๋๋ค.
public void getImage(String filePath, HttpServletResponse response) throws Exception{
File file = new File(filePath);
if(!file.isFile()){
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
out.write("<script type='text/javascript'>alert('์กฐํ๋ ์ ๋ณด๊ฐ ์์ต๋๋ค.'); self.close();</script>");
out.flush();
return;
}
FileInputStream fis = null;
new FileInputStream(file);
BufferedInputStream in = null;
ByteArrayOutputStream bStream = null;
try {
fis = new FileInputStream(file);
in = new BufferedInputStream(fis);
bStream = new ByteArrayOutputStream();
int imgByte;
while ((imgByte = in.read()) != -1) {
bStream.write(imgByte);
}
String type = "";
String ext = FilenameUtils.getExtension(file.getName());
if (ext != null && !"".equals(ext)) {
if ("jpg".equals(ext.toLowerCase())) {
type = "image/jpeg";
} else {
type = "image/" + ext.toLowerCase();
}
} else {
LOGGER.debug("Image fileType is null.");
}
response.setHeader("Content-Type", type);
response.setContentLength(bStream.size());
bStream.writeTo(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
} catch (Exception e) {
LOGGER.debug("{}", e);
} finally {
if (bStream != null) {
try {
bStream.close();
} catch (Exception est) {
LOGGER.debug("IGNORED: {}", est.getMessage());
}
}
if (in != null) {
try {
in.close();
} catch (Exception ei) {
LOGGER.debug("IGNORED: {}", ei.getMessage());
}
}
if (fis != null) {
try {
fis.close();
} catch (Exception efis) {
LOGGER.debug("IGNORED: {}", efis.getMessage());
}
}
}
}
test
'Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JXLS] ์์ ๋ค์ด๋ก๋ (3) | 2021.05.06 |
---|---|
[Mybatis] ๋ฐฉ๊ธ insert ๊ฐ select ํ๊ธฐ <selectKey> (6) | 2021.05.04 |
[java] mybatis foreach ๋ค์ค insert (0) | 2021.04.06 |
[springloaded] java file ์์ ํ tomcat ์ฌ์์ ์์ด ๋ฐ์ : ์ฌ๋ก๋ฉ ์์คํ (0) | 2021.03.23 |
[eclipse] tomcat server ํ๋ก์ ํธ ์ ํ์ด์๋ ๊ฒฝ์ฐ (0) | 2021.03.22 |